eof

braver deliverable at gmail.com
Fri Nov 23 18:56:20 EST 2007


On Nov 22, 8:04 pm, Neil Cerutti <horp... at yahoo.com> wrote:
> I think Python is well rid of such a seldomly useful source of
> confusion.

So all that code folks wrote in Algol-like languages, -- e.g. this
works in Ada, --

while not End_of_File(f) loop
   --
end if;

-- are confusing?  Why not interpret it as reading until ^D on a
pipe?  And plain files work fine.  (What would Ruby do?:)
Historically, is it possible to trace the eof-related design decision
in stdlib?  Most languages have the look-ahead eof, so when Python was
codified, there should gave been some decisions made.

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:?  I assume it'll
do the right thing if our file ends in \n.  What if the last line is
not \n-terminated?

Cheers,
Alexy



More information about the Python-list mailing list