Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18587
| References | (2 earlier) <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> <CALwzidn5zJVYPsViSx-SV25Ef5qSsY0d8bX=6rcdvPBu8UydZw@mail.gmail.com> <mailman.4464.1325813187.27778.python-list@python.org> <fa7b56e3-68b1-4b37-834d-48ab73177baf@k28g2000yqn.googlegroups.com> <4F0663E8.4090302@mrabarnett.plus.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2012-01-06 00:41 -0700 |
| Subject | Re: Help with python-list archives |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4472.1325835693.27778.python-list@python.org> (permalink) |
On Thu, Jan 5, 2012 at 8:00 PM, MRAB <python@mrabarnett.plus.com> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-05 14:44 -0800
Re: Help with python-list archives Miki Tebeka <miki.tebeka@gmail.com> - 2012-01-05 15:39 -0800
Re: Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-05 15:52 -0800
Re: Help with python-list archives Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-05 17:10 -0700
Re: Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-05 16:45 -0800
Re: Help with python-list archives MRAB <python@mrabarnett.plus.com> - 2012-01-06 01:27 +0000
Re: Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-05 18:14 -0800
Re: Help with python-list archives MRAB <python@mrabarnett.plus.com> - 2012-01-06 03:00 +0000
Re: Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-05 20:01 -0800
Re: Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-05 20:08 -0800
Re: Help with python-list archives Chris Angelico <rosuav@gmail.com> - 2012-01-06 15:12 +1100
Re: Help with python-list archives Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-06 00:45 -0700
Re: Help with python-list archives Anssi Saari <as@sci.fi> - 2012-01-10 16:47 +0200
Re: Help with python-list archives Chris Angelico <rosuav@gmail.com> - 2012-01-06 15:11 +1100
Re: Help with python-list archives Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-06 00:41 -0700
Re: Help with python-list archives random joe <pywin32@gmail.com> - 2012-01-06 16:55 -0800
Re: Help with python-list archives Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-05 17:02 -0700
csiph-web