On 2007-11-23, braver <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list