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!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'expected.': 0.09; 'pointers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'backward': 0.16; 'operation.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'later': 0.20; 'help.': 0.21; 'seems': 0.21; 'header:User- Agent:1': 0.23; 'file.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'direction': 0.30; 'file': 0.32; 'covered': 0.32; 'basic': 0.35; '8bit%:86': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'tell': 0.60; 'more': 0.64; 'received:46': 0.66; 'otten': 0.84; 'inefficient': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: fseek In Compressed Files Date: Thu, 30 Jan 2014 17:02:58 +0200 References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 46.211.182.240 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391094182 news.xs4all.nl 2924 [2001:888:2000:d::a6]:46329 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65017 30.01.14 13:28, Peter Otten написав(ла): > 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)? I don't recommend to seek backward in compressed file. This is very inefficient operation.