[Tutor] is there an explicit eof to test in Py 3?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Apr 22 17:25:09 CEST 2013
On 22 April 2013 02:35, Jim Mooney <cybervigilante at 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.
In Python the rules for this are very simple. Strings compare equal if
they have exactly the same sequence of characters. Otherwise they
compare unequal.
> 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?
Why do you want to do this? The only reason I can think of is to avoif
buffering. Generally, the for loop is not just easier and clearer but
also more efficient (because of the buffering). It also allows you to
write code that can work just as easily with anything that is iterable
such as a list of strings.
Oscar
More information about the Tutor
mailing list