I’m trying to open a .txt file in Python with the following function.
def get_my_string():
"""Returns a string of the text"""
f = open("/home/Documents/text.txt", 'r')
string = str(f.read())
f.close()
return string
I want “string” to be a string of the text from the opened file. However, after calling the function above, “string” is an empty list.
1 Answer