eof
Neil Cerutti
horpner at yahoo.com
Thu Nov 22 12:04:25 EST 2007
On 2007-11-22, Hrvoje Niksic <hniksic at xemacs.org> wrote:
> "Diez B. Roggisch" <deets at nospam.web.de> writes:
>
>>>> Language comparisons are sometimes good. They are best when
>>>> they are free of FUD.
>>>
>>> So why Python's IO cannot yield f.eof() as easily as Ruby's can? :)
>>
>> Because that requires buffering, something that affects speed.
>
> I don't get it, Python's files are implemented on top of stdio
> FILE objects, which do buffering and provide EOF checking (of
> the sort where you can check if a previous read hit the EOF,
> but still). Why not export that functionality?
You have to make a failed read attempt before feof returns true.
>> Considering your own repeated remarks about "I'd only use ruby
>> if it wasn't slower than Python", I'd think you could value
>> that.
>
> I see no reason why exposing the EOF check would slow things down.
I think it's too low level, and so doesn't do what naive users
expect. It's really only useful, even in C, as part of the
forensic study of a stream in an error state, yet naive C
programmers often write code like:
while (!f.feof()) {
/* Read a line and process it.
}
...and are flumoxed by the way it fails to work.
I think Python is well rid of such a seldomly useful source of
confusion.
--
Neil Cerutti
More information about the Python-list
mailing list