I'm currently learning how to create a spell checker in Python. In some tutorials I see something like the following:
def ReadDictionaryFile(dictionaryfilename):
dictionarywords = [] # stores words in a list
inputfile = open(dictionaryfilename, "r")
for line in inputfile: # iterate over the lines of the file
word = line.strip() # whitespace removed
dictionarywords.append(word) # appends word to the list
inputfile.close()
return dictionarywords
But I don't understand how python knows to separate it out into lines.
In for line in inputfile:, "line" is just a variable, so what part of the code is actually telling it stop at \n?
Is there some built in feature in python where for loops iterating through text just start the next iteration when they encounter \n? I couldn't find any info on this...
Any help appreciated!