小编典典

如何将整个文件读入python列表中?

python

我想将整个文件读入python列表中,任何人都知道怎么做?


阅读 219

收藏
2021-01-20

共1个答案

小编典典

print "\nReading the entire file into a list."
text_file = open("read_it.txt", "r")
lines = text_file.readlines()
print lines
print len(lines)
for line in lines:
    print line
text_file.close()
2021-01-20