I know this is probably a question asked before and I have searched for some answers, for example, this one.
But I am still very confused and I want to ask it again for a definite answer.
My question is: Is an empty line with only whitespace characters, such as the newline character (/n), when placed as the last line of a file, always treated as EOF by Python? What about other languages such as PHP, Javascript etc? Any OS platform differences?
For example, in my python3 code, I have a file to process:
some text at line 10
some more text at line 11
nothing (last line of file)
My code recognizes the last line as EOF, and raises StopIteration exception. If I do not have the last empty line, the code works without the exception (I am using open() as f: for line in f
so literally it does have EOF but captured internally). The text editor I used is VisualStudio and notepad, tried both.
For the same text file, if I concatenate it to itself, the new file does not have the newline in between them. That's the reason I think the last empty line is just treated as EOF and ignored.
Thank you.