eof
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Wed Nov 21 22:12:19 EST 2007
On Wed, 21 Nov 2007 15:17:14 -0800, braver 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.
Why? For some file-like objects, the OS can't tell if you're at EOF until
you actually try to read.
The usual way to deal with EOF in Python is not to bother.
fp = open("filename", "r")
for line in fp:
do_something_with(line)
# When we exit the loop, we're at EOF.
What are you doing that needs more hands-on control?
--
Steven.
More information about the Python-list
mailing list