I have a file compressed with bz2 and a function that expects a file handle.
When I decompress the bz2 file I get a string (binary) not a file handle.
Here is what I have that does not work. There is no error (thats a seperate
issue) CelFile.read just fails to read the data(string).
from
On 2014-05-18 19:53, Vincent Davis wrote:
I have a file compressed with bz2 and a function that expects a
file handle. When I decompress the bz2 file I get a string (binary)
not a file handle.
from bz2 import decompress,
with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle
handle.
from bz2 import decompress,
with open('Tests/Affy/affy_v3_ex.CEL.bz2', 'rb') as handle:
cel_data = decompress(handle.read())
When I try (without the Bio.Affy which isn't part of the stdlib), I
get correct bytes from this:
tim@bigbox:~$ echo hello world test.txt
tim@bigbox
On Sun, May 18, 2014 at 8:38 PM, Vincent Davis vinc...@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')
On Sun, May 18, 2014 at 9:44 PM, Ian Kelly ian.g.ke...@gmail.com wrote:
You can just use bz2.open:
with bz2.open('test.txt.bz2', 'rt', encoding='ascii') as f:
... print(f.read())
Thanks I like that better then my solution.
Vincent Davis
720-301-3003
--