1def readFile(fileName):
2 fileObj = open(fileName, "r") #opens the file in read mode
3 words = fileObj.read().splitlines() #puts the file into an array
4 fileObj.close()
5 return words
1text_file = open("filename.dat", "r")
2lines = text_file.readlines()
3print lines
4print len(lines)
5text_file.close()
1# The best and most simple way is to use SimpleList
2# Install: pip install simplelist
3from simplelist import listfromtxt
4from simplelist import txtfromlist
5
6newList = listfromtxt('myFile.txt') # Make A List From A TXT File
7txtfromlist('myFile.txt', myList) # Read A Python List Into A TXT File