Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'pointers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; 'compression': 0.16; 'offsets': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'referencing': 0.16; 'remembered': 0.16; 'slow,': 0.16; 'subsequently': 0.16; 'temp': 0.16; 'types,': 0.16; 'later': 0.20; 'help.': 0.21; 'non': 0.24; 'file.': 0.24; 'header:X-Complaints- To:1': 0.27; 'tried': 0.27; "doesn't": 0.30; 'compared': 0.30; 'direction': 0.30; 'mode': 0.30; 'went': 0.31; 'easier': 0.31; 'lines': 0.31; 'os,': 0.31; 'file': 0.32; 'there.': 0.32; 'text': 0.33; 'but': 0.35; 'building': 0.35; 'version': 0.36; 'module.': 0.36; 'possible': 0.36; 'should': 0.36; 'too': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'realize': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'tell': 0.60; 'save': 0.62; "you've": 0.63; 'show': 0.63; 'subject::': 0.85; 'imagine': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:fseek In Compressed Files Date: Thu, 30 Jan 2014 06:55:32 -0500 (EST) Organization: news.gmane.org References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> X-Gmane-NNTP-Posting-Host: dpc6744192077.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391082792 news.xs4all.nl 2904 [2001:888:2000:d::a6]:53795 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64985 Ayushi Dalmia Wrote in message: > Hello, > > 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. > Start with the zlib module. Note that it doesn't handle all possible compression types, like compress and pack. I don't imagine that seeking to a line in a compressed text file would be any easier than a non compressed one. Try using gzip.open in a text mode to get a handle, then loop through it line by line. If you save all the offsets in a list, you should subsequently be able to seek to a remembered offset. But realize it'll be horribly slow, compared to a non compressed one. Consider using readlines and referencing the lines from there. Or building a temp file if too big for ram. If this is not enough, tell us your Python version and your os, and show what you've tried and what went wrong. -- DaveA