fseek In Compressed Files
Peter Otten
__peter__ at web.de
Thu Jan 30 06:28:32 EST 2014
Ayushi Dalmia wrote:
> I need to randomly access a bzip2 or gzip file. How can I set the offset
> for a line and later retreive the line from the file using the offset.
> Pointers in this direction will help.
with gzip.open(filename) as f:
f.seek(some_pos)
print(f.readline())
f.seek(some_pos)
print(f.readline())
seems to work as expected. Can you tell a bit more about your usecase (if it
isn't covered by that basic example)?
More information about the Python-list
mailing list