txt pour lister python
with open('names.txt', 'r') as f:
myNames = [line.strip() for line in f]
Relieved Reindeer
with open('names.txt', 'r') as f:
myNames = [line.strip() for line in f]
def readFile(fileName):
fileObj = open(fileName, "r") #opens the file in read mode
words = fileObj.read().splitlines() #puts the file into an array
fileObj.close()
return words
f = open(filename, "r")
listItems = f.read().splitlines()
# read file in a string list
with open(fileName) as f:
lineList = f.readlines()
text_file = open("filename.dat", "r")
lines = text_file.readlines()
print lines
print len(lines)
text_file.close()
# 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