Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'string.': 0.05; 'binary': 0.07; 'subject:file': 0.07; 'subject:skip:b 10': 0.07; "'rb')": 0.16; 'posting,': 0.16; 'stringio': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; 'received:google.com': 0.35; 'handle': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:o 30': 0.61; 'subject:handle': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=bM69UKS0K9cM1dLTVOgt0Q5E6qd36RkjWHZ0Vh4vHjk=; b=em0vjlXTrn4oPLoizeV5bVp0A/6Ehy2Ogd+n0fK2sy3vjoeoqda79THfB7KCUIyJac Ip0RYT9XLl6bVP6VK4lWykEsSQG6dettNA+f3Mhr3qRMWRqxF4q5MFWBW2tkY6Opa3SZ zcVCkCLaIbRN+5JwuUxzfZfbaf7RIWESo7uvymhLuRcj4sDOU6WGY7iA7kGIe5n2DNiH Qb1/PmK9EfuVBxKeSkJvpmxHpPEfA0yr3paZUHij50Y7mcaqv15qTFZFL71z3yqznTS6 nzqSYhTzQN31TA+QQYH09oeTTLglIaX9GKWgV8BIjr/AYw36UDYU5sMj+s96M1XwzZSc 5ZmQ== X-Received: by 10.68.249.2 with SMTP id yq2mr39500786pbc.70.1400471093105; Sun, 18 May 2014 20:44:53 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <20140518213256.5a0f2d71@bigbox.christie.dr> From: Ian Kelly Date: Sun, 18 May 2014 21:44:12 -0600 Subject: Re: bz2.decompress as file handle To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400471096 news.xs4all.nl 2925 [2001:888:2000:d::a6]:41992 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71743 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: > 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!