I have placed a list in a text file. I want python to read the text file and return the contents as a list. However, it is instead reading the content as a string:
Text file:
['a','b','c']
Python:
ids=[]
writtenFile =open('file.txt')
readFile=writtenFile.read()
ids= readFile
writtenFile.close()
print ids
What is returned is ['a','b','c'] as a string, not as a list or just text. Is there a way I can retrieve ['a','b','c'] from the text file and then store this in the ids string so that ids is a list ['a','b','c'] and not the string ? "['a','b','c']"?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…