[Tutor] is there an explicit eof to test in Py 3?
Dave Angel
davea at davea.name
Mon Apr 22 06:32:12 CEST 2013
On 04/21/2013 09:35 PM, Jim Mooney 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.
>
> Yes, I know the easy way is a for loop, which automatically breaks on
> eof, but at times I want to use a while loop and break out of it
> explicitly on eof. But I can't seem to find an explicit eof marker in
> python. Is there one?
>
A little experimenting could have told you the answer. readline()
returns a newline character for a blank line, and an empty string for
end of file.
--
DaveA
More information about the Tutor
mailing list