What is the best way to handle a missing newline in the following case

chad cdalten at gmail.com
Fri Nov 5 16:16:41 CET 2010


I have an text file with the following numbers

1
3
5
7
3
9



Now the program reads in this file. When it encounters a '\n', it will
do some stuff and then move to the next line. For example, it will
read 1 and then '\n'. When it sees '\n', it will do some stuff and go
on to read 3.

The problem is when I get to the last line. When the program sees '\n'
after the 9, everything works fine. However, when there isn't a '\n',
the program doesn't process the last line.

What would be the best approach to handle the case of the possible
missing '\n' at the end of the file?



More information about the Python-list mailing list