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
-
What do you mean? Is it something like this?: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=python]Code:word1, word2, word3 ..., word4, word5, word6 ...
inFile = file("test.txt" )
wordlist = [word.strip() for word in inFile.read().s plit(",")]
wordlist.sort()
[/code] -
Yep. Presuming that each word is on its own line followed by some sort of line-terminator (new-line):[CODE=python]fileName = r"C:\this\is\a\ path\theFile.tx t"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