On Sun, Apr 21, 2013 at 9:35 PM, Jim Mooney <cybervigila...@gmail.com> wrote: > I'm reading a book that suggests finding EOF when the readLine == "" > > But wouldn't that end erroneously on blank lines, that really contain > '\n', in which case more lines might follow? What 'empties' are > considered equal in Python? I'm coming from javascript which has a > cluster of rules for that.
The newline (os.linesep) isn't stripped, though depending on the "newline" option for open() it may be translated. You shouldn't be testing equality. You know that reading from a file returns either bytes or a string, so just rely on the boolean value. Any type that implements __len_ (collections.abc.Sized) has an implicit boolean value: http://docs.python.org/3/reference/datamodel.html#object.__bool__ For example: while True: line = file.readline() if not line: break process(line) _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor