Re: file object and eof

2006-08-15 Thread Fredrik Lundh
KraftDiner wrote: > how about?!: > > def eof(fileobj): >curloc = fileobj.tell() >ofloc = fileobj.seek(0,2) >fileobj.seek(curloc, 0) >if ofloc >= curloc: > return True >return False this doesn't work with text files on platforms that translates line endings, it doesn't

Re: file object and eof

2006-08-15 Thread Steve Holden
KraftDiner wrote: [...] > how about?!: > > def eof(fileobj): >curloc = fileobj.tell() >ofloc = fileobj.seek(0,2) >fileobj.seek(curloc, 0) >if ofloc >= curloc: > return True >return False > Ignoring the errors in your file manipulation, think about replacing the last th

Re: file object and eof

2006-08-15 Thread [EMAIL PROTECTED]
KraftDiner wrote: > how about?!: > > def eof(fileobj): >curloc = fileobj.tell() >ofloc = fileobj.seek(0,2) >fileobj.seek(curloc, 0) >if ofloc >= curloc: > return True >return False 1. At least on python 2.3, seek always returns None--did that change in 2.4? I added a tel

Re: file object and eof

2006-08-15 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, 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?

Re: file object and eof

2006-08-15 Thread KraftDiner
Grant Edwards wrote: > On 2006-08-15, KraftDiner <[EMAIL PROTECTED]> wrote: > > > I open a file in python by > > f = open('filename', mode='rb') > > > > how can I tell if I am at the end of file? > > I don't believe you can unless you try to read from the file. > > > f.eof() isn't implmented. > >

Re: file object and eof

2006-08-15 Thread Grant Edwards
On 2006-08-15, KraftDiner <[EMAIL PROTECTED]> wrote: > I open a file in python by > f = open('filename', mode='rb') > > how can I tell if I am at the end of file? I don't believe you can unless you try to read from the file. > f.eof() isn't implmented. > > How can I implement its functionallity?

Re: file object and eof

2006-08-15 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, KraftDiner wrote: > I open a file in python by > f = open('filename', mode='rb') > > how can I tell if I am at the end of file? > f.eof() isn't implmented. > > How can I implement its functionallity? Try to read something. If the empty string is returned you are at the

file object and eof

2006-08-15 Thread KraftDiner
I open a file in python by f = open('filename', mode='rb') how can I tell if I am at the end of file? f.eof() isn't implmented. How can I implement its functionallity? Thanks. B. -- http://mail.python.org/mailman/listinfo/python-list