If you have a text file that say has a list of 1000 plus words is there a way that you can recall that file without having to type the whole list out word by word and which will also allow you to once recalled sort the list and do other things to it
Recalling Lists
Collapse
X
-
Originally posted by texas22If you have a text file that say has a list of 1000 plus words is there a way that you can recall that file without having to type the whole list out word by word and which will also allow you to once recalled sort the list and do other things to it
text.txt
Code:word1, word2, word3 ..., word4, word5, word6 ...
inFile = file("test.txt" )
wordlist = [word.strip() for word in inFile.read().s plit(",")]
wordlist.sort()
[/code] -
Originally posted by texas22If you have a text file that say has a list of 1000 plus words is there a way that you can recall that file without having to type the whole list out word by word and which will also allow you to once recalled sort the list and do other things to it
# I just make up variable names, you can use you own
inputFile = open(fileName)
wordList = inputFile.readl ines()
inputFile.close ()
wordList.sort()
# Writing is just as easy, just open a file in (w)rite mode
fileName = "whatever"
outputFile = open(fileName, "w")
outputFile.writ elines(wordList )
outputFile.clos e()[/CODE]
Which would, of course, keep the new-line chrs with each word.Comment
Comment