On Nov 24, 12:03 am, MonkeeSage <[EMAIL PROTECTED]> wrote: > > class open(file): > def __init__(self, name): > self.size = os.stat(name).st_size > file.__init__(self, name) > def eof(self): > return self.tell() == self.size > > f = open('tmp.py') > print f.eof() # False > f.read() > print f.eof() # True
This is a bad idea because self.size is not guaranteed to be accurate. For files in /proc, /sys, and for fifo's, unix domain sockets, etc, you will get incorrect results. Always write your algorithm to simply read until there is no more data. Once that happens, you are at EOF. EOF is a property of a file only after reading didn't return any data. If you use EOF in the middle of reading a file, it will never be accurate (or it will be slow). -JJ -- http://mail.python.org/mailman/listinfo/python-list