I want to read an entire file into a python list any one knows how to?
Simpler:
with open(path) as f:
myList = list(f)
If you don't want linebreaks, you can do list(f.read().splitlines())
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With