eof

Neil Cerutti horpner at yahoo.com
Wed Nov 21 21:06:58 EST 2007


On 2007-11-21, braver <deliverable at gmail.com> wrote:
> I'd like to check, for a filehandle f, that EOF has been reached on
> it.  What's the way to do it?  I don't want to try/except on EOF, I
> want to check, after I read a line, that now we're in the EOF state.
> In Ruby it's f.eof:
>
> In Ruby:
>>> f = File.open("jopa")
>=> #<File:jopa>
>>> f.read()
>=> "jopa\n"
>>> f.eof
>=> true
>
> Is there a Python analog?

Yes.

>>> f = file('jopa')
>>> f.read()
'jopa\n'

...and in both Ruby and Python you are at EOF by definition.
There's no need to check.

-- 
Neil Cerutti



More information about the Python-list mailing list