eof

Neil Cerutti horpner at yahoo.com
Fri Nov 23 19:36:30 EST 2007


On 2007-11-23, braver <deliverable at gmail.com> wrote:
> Can we say that f.eof() in fact can check for EOF right after
> we've read all characters from a file, but before a failed
> attempt to read beyond?  In Python's idiom,
>
> for line lin file:
>    # look at a line
>    # we can tell eof occurs right here after the last line
>
> After the last line, we've read all bytes but didn't try a new
> line yet -- is it the semantics of the for line in file:?  

Yes. After the above construction, there's no need to check for
eof.

> I assume it'll do the right thing if our file ends in \n.  What
> if the last line is not \n-terminated?

Nothing bad happens as far as I know, but it may depend on the
underlying clib.

-- 
Neil Cerutti



More information about the Python-list mailing list