Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Nov 22 04:12:19 CET 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:
# When we exit the loop, we're at EOF.

What are you doing that needs more hands-on control?


More information about the Python-list mailing list