file object and eof

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Aug 15 16:03:17 EDT 2006


In <1155668786.644843.192830 at m79g2000cwm.googlegroups.com>, KraftDiner
wrote:

>> > f.eof() isn't implmented.
>> >
>> > How can I implement its functionallity?
>>
>> You don't, generally.
>>
>> There's probably a better, "more Pythonic" way to accomplish
>> your goal, but you're going to have to tell us what it is.
>>
> 
> how about?!:
> 
> def eof(fileobj):
>    curloc = fileobj.tell()
>    ofloc = fileobj.seek(0,2)
>    fileobj.seek(curloc, 0)
>    if ofloc >= curloc:
>       return True
>    return False

Works only for files that support `tell()` and `seek()`.  What's your use
case for `eof()`?

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list