Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: =?UTF-8?B?UmU6IFdoYXQgaW50ZXJmYWNlIGlzIGEg4oCYUG9wZW4uc3Rkb3V04oCZIHByZXNlbnRpbg==?= =?UTF-8?B?Zz8=?= Date: Wed, 23 Dec 2015 22:30:02 -0600 Lines: 19 Message-ID: References: <85d1twzlj2.fsf@benfinney.id.au> <858u4kzkyp.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 6m8+oqS06Bl/l7MPp9bkegUk9mDlUf99FjJ+p2pOplQw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'descriptor': 0.09; 'python': 0.10; 'wed,': 0.15; "'r')": 0.16; '23,': 0.16; 'dup': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'file.': 0.22; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; 'open': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'skip:o 20': 0.38; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'close': 0.61; 'subjectcharset:utf-8': 0.71; '8bit%:27': 0.72 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:content-transfer-encoding; bh=+8RngUpdhN1xGVbiHqscZQh7oI8/bYlOraAWtjrSEQs=; b=zsRNqNQPvrvspGNj8mkt6spAAlEJzleAqvs4YvTQca/kGVoaOTsQWQONmsWGt7+SFY 5uvL3FMu8IIvC+gfDa+Hmvaz7IDDFbnqu5jbYUIH6Ugy0hh4zHCdIDVc2pnWTO/cCEV+ NItyd0ya4MnfAgLx8iyNmTQSmXwRNKUhlao62TdBRAOLyeD4r7vQl0TFQtu1ZYcMULeL mFQqIIc32DMjvCHB5Rz5/NOVDxHaCkOdWVs8b2A0hSFmSBfc+kjUl+BJwYymX6ew0TPL ovqmZXEuI0uyfZFVGohL6OsoXk2QK1QJm8sOG7IfB6d+Rv8hgOk/Aoe5q4QnGCBi6o/V J2iw== X-Received: by 10.50.156.35 with SMTP id wb3mr27375514igb.55.1450931442399; Wed, 23 Dec 2015 20:30:42 -0800 (PST) In-Reply-To: <858u4kzkyp.fsf@benfinney.id.au> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100792 On Wed, Dec 23, 2015 at 7:36 PM, Ben Finney wr= ote: > So how do I get from a Python 2 =E2=80=98file=E2=80=99 object, to whateve= r > =E2=80=98io.TextIOWrapper=E2=80=99 wants? I would dup the file descriptor and close the original file. Then open the file descriptor using io.open: >>> p =3D subprocess.Popen(['uname'], stdout=3Dsubprocess.PIPE) >>> fd =3D os.dup(p.stdout.fileno()) >>> fd 4 >>> p.stdout.close() >>> fout =3D io.open(fd, 'r') >>> fout <_io.TextIOWrapper name=3D4 encoding=3D'UTF-8'> >>> fout.read() u'Linux\n'