Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71743 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2014-05-18 21:44 -0600 |
| Last post | 2014-05-18 21:44 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: bz2.decompress as file handle Ian Kelly <ian.g.kelly@gmail.com> - 2014-05-18 21:44 -0600
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-05-18 21:44 -0600 |
| Subject | Re: bz2.decompress as file handle |
| Message-ID | <mailman.10121.1400471096.18130.python-list@python.org> |
On Sun, May 18, 2014 at 8:38 PM, Vincent Davis <vincent@vincentdavis.net> wrote:
> Well after posting, I think I figured it out.
> The key is to use StringIO to get a file handle on the string. The fact that
> it is binary just complicates it a little.
>
> with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle:
> cel_data = StringIO(decompress(handle.read()).decode('ascii'))
You can just use bz2.open:
>>> with bz2.open('test.txt.bz2', 'rt', encoding='ascii') as f:
... print(f.read())
...
hello!
Back to top | Article view | comp.lang.python
csiph-web