Read Text File as a String

user_6939821 avatar
user_6939821
python
08/02/2023 1:49 PM
212 B
19
Indexable
#open text file in read mode
text_file = open("D:/data.txt", "r")
 
#read whole file to a string
data = text_file.read()
 
#close file
text_file.close()
Editor is loading...