xxxxxxxxxx
import csv
with open('filename.csv', 'r') as fd:
reader = csv.reader(fd)
for row in reader:
# do something
xxxxxxxxxx
text_file = open("filename.dat", "r")
lines = text_file.readlines()
print lines
print len(lines)
text_file.close()
xxxxxxxxxx
# The best and most simple way is to use SimpleList
# Install: pip install simplelist
from simplelist import listfromtxt
from simplelist import txtfromlist
newList = listfromtxt('myFile.txt') # Make A List From A TXT File
txtfromlist('myFile.txt', myList) # Read A Python List Into A TXT File