eof

Wayne Brehaut wbrehaut at mcsnet.ca
Thu Nov 22 02:37:32 EST 2007


On Wed, 21 Nov 2007 17:06:15 -0800 (PST), braver
<deliverable at gmail.com> wrote:

>On Nov 22, 3:41 am, Wayne Brehaut <wbreh... at mcsnet.ca> wrote:
>> If you have PythonWin 2.5.1 (r251:54863, May  1 2007, 17:47:05) [MSC v.1310
>> 32 bit (Intel)] on win32.for example, using Help, Index, eof gives:
>>

8< ===

>
> HTH?

>Nope!  I don't want to buffer input myself, and don't want to store
>look-ahead and push it back.  f.read()/readline() is not a non-
>destructive check, and thus won't do.

Your original statement was: "I'd like to check, for a filehandle f,
that EOF has been reached on it." You now appear to be "upping the
ante" as though you're more interested in attacking what you perceive
as an omission in Python than in doing what you originally stated.

>Well folks compare scripting languages all the time, and surely Ruby
>is closer to Python than C++.  

If I  didn't abhor smileys and text substitutes you might have caught
on that this was partly "just kidding", but not completely: since
Python is implemented in C/C++ it makes perfect sense to see what's
readily available there that might account for how one would do it in
Python if he really thought it necessary. (As others have noted, it's
not necessary.)

So what Python is "closer to" is not the point--and there's no
standard way of measuring that that I know of?

>Since Ruby can do f.eof, which is
>easily found in its references, and Python can't, or its EOF can't
>easily be found -- the one *equivalent* to a semantically clear
>Ruby's, or Pascal's IIRC, f.eof -- something's missing here...
>Why do I have to count sizes of lines read and compare it to some
>filesize 

Why would you think that it's you doing the counting? If you insist,
write your own trivial eof() and call it so you won't have to fret
about how it's discovering whether you're at EOF.

>or do other weird tricks just to see, in a way not changing
>my input stream, whether it's at the, well, EOF?

As others have already pointed out, "because it's seldom necessary in
Python". If you really think you need to do it the way you're implying
in Python, you're probably mistaken. You should do it the pythonic way
instead of complaining about not finding the exact equivalent to how
you would do it in some other language. 

"Python is not Ruby."

wwwayne


>Cheers,
>Alexy



More information about the Python-list mailing list