xreadlines() being used with file.tell() and file.seek()
Jeff Epler
jepler at unpythonic.net
Mon Mar 15 18:39:18 EST 2004
xreadlines() internally does something like this [using the Python 2.3
generator function syntax]:
def xreadlines(f):
while 1:
chunk = f.readlines(sizehint)
if not chunk: break
for line in chunk:
yield line
Unless you happen to seek() just as xreadlines is between chunks, the
result of the seek won't be seen until later, when the next chunk is
read. Your input file is far too small to notice this effect.
Similarly, after you've started an xreadlines() on a file, the file will
tell() you that it is after the end of all the lines in chunk.
xreadlines is supposed to be fast, and it really doesn't care what other
file-like object assumptions it invalidates to get that result.
Jeff
More information about the Python-list
mailing list