Generic lazily seekable file-like object wrapper?

John J Lee jjl at pobox.com
Tue Nov 19 14:35:05 EST 2002


Does anybody have a (free) file-like object wrapper that adds a
seek method and allows lazily read()ing from the wrapped file-like
object?  ie.:

fh = urlopen("http://foo.bar.com/")  # any old file-like object
assert hasattr(fh, "read") or hasattr(fh, "readline")
assert not hasattr(fh, "seek")
sfh = LazilySeekableFile(fh)  # doesn't call fh.read
do_something(sfh.read(100))  # calls fh.read
sfh.seek(0)  # doesn't call fh.seek
print sfh.read(100)  # doesn't call fh.read or fh.readline


John



More information about the Python-list mailing list