Re: bz2.decompress as file handle

2014-05-18 Thread Vincent Davis
On Sun, May 18, 2014 at 9:44 PM, Ian Kelly 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 -- https://mail.python.org/mailman/listinfo/

Re: bz2.decompress as file handle

2014-05-18 Thread Ian Kelly
On Sun, May 18, 2014 at 8:38 PM, Vincent Davis 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: > ce

Re: bz2.decompress as file handle

2014-05-18 Thread Vincent Davis
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')) Vinc

Re: bz2.decompress as file handle

2014-05-18 Thread Tim Chase
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: >

bz2.decompress as file handle

2014-05-18 Thread Vincent Davis
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 Bio.Affy