Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'mrab': 0.04; 'subject:python': 0.10; 'intermediate': 0.15; 'gzip': 0.16; 'stringio': 0.16; 'received:74.125.82.44': 0.16; 'received:mail- ww0-f44.google.com': 0.16; 'subject:Help': 0.17; 'wrote:': 0.18; 'instance': 0.18; 'jan': 0.19; 'memory': 0.21; 'subject:list': 0.21; 'header:In-Reply-To:1': 0.22; 'creating': 0.25; 'import': 0.27; 'message-id:@mail.gmail.com': 0.28; 'pm,': 0.29; 'necessary.': 0.32; 'thu,': 0.32; 'sort': 0.33; "won't": 0.33; 'to:addr:python-list': 0.34; 'received:74.125.82': 0.35; 'file': 0.36; 'subject:with': 0.36; 'received:74.125': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'could': 0.37; 'using': 0.38; 'some': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.40; 'skip:o 30': 0.63; '2012': 0.67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=EZWbyS6YCVAaLBFSBB9FNU9Tpj+UjLKTIKQO5if+spY=; b=EndvtR9T0R2dmESFGvHsw2W3VE7JsRCHYMJ8tbAWHNSSmAAn7N6abVQfM9Hoa2uhhu 5LGF1XwEhA1JuFckA+SuLFbwNe/+OiZyhTER3YD1HaMbMSswuaaZrwv+zjI30BT3yWeF dR1cMHMnjHpubuOzZALwSq+yEjaWNk7gg0E50= MIME-Version: 1.0 In-Reply-To: <4F0663E8.4090302@mrabarnett.plus.com> References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> <4F0663E8.4090302@mrabarnett.plus.com> From: Ian Kelly Date: Fri, 6 Jan 2012 00:41:01 -0700 Subject: Re: Help with python-list archives To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325835693 news.xs4all.nl 6922 [2001:888:2000:d::a6]:38558 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18587 On Thu, Jan 5, 2012 at 8:00 PM, MRAB wrote: > import gzip > > in_file = gzip.open(r"C:\2012-January.txt.gz") > out_file = open(r"C:\2012-January.txt.tmp", "wb") > out_file.write(in_file.read()) > in_file.close() > out_file.close() > > in_file = gzip.open(r"C:\2012-January.txt.tmp") > out_file = open(r"C:\2012-January.txt", "wb") > out_file.write(in_file.read()) > in_file.close() > out_file.close() One could also avoid creating the intermediate file by using a StringIO to keep it in memory instead: import gzip from cStringIO import StringIO in_file = gzip.open('2012-January.txt.gz') tmp_file = StringIO(in_file.read()) in_file.close() in_file = gzip.GzipFile(fileobj=tmp_file) out_file = open('2012-January.txt', 'wb') out_file.write(in_file.read()) in_file.close() out_file.close() Sadly, GzipFile won't read directly from another GzipFile instance (ValueError: Seek from end not supported), so some sort of intermediate is necessary.