Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100793

Re: What interface is a ‘Popen.stdout’ presenting?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: What interface is a ‘Popen.stdout’ presenting?
Date Thu, 24 Dec 2015 15:40:06 +1100
Lines 29
Message-ID <mailman.102.1450932021.2237.python-list@python.org> (permalink)
References <85d1twzlj2.fsf@benfinney.id.au> <858u4kzkyp.fsf@benfinney.id.au> <CACL+1asM6wXoQFfwmHZ3nn70N3x+QL5POm88eqpsmEvbpDZVsQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de yDlS+ZoKgkzlZOGsgCUNhgTzRdoNITykZvn5I2PCV8sg==
Cancel-Lock sha1:kqDWjGxwV5Ji1z2m3JmBHcx9Gog=
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'wrapper': 0.07; 'descriptor': 0.09; 'mode,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'underlying': 0.09; 'python': 0.10; 'wed,': 0.15; '23,': 0.16; '8bit%:26': 0.16; 'dup': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'stream.': 0.16; 'those,': 0.16; 'wrote:': 0.16; 'thanks.': 0.18; '2015': 0.20; 'file.': 0.22; 'dec': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; '(e.g.': 0.27; 'object,': 0.27; 'code': 0.30; 'stream': 0.33; 'wrap': 0.33; 'open': 0.33; 'file': 0.34; 'text': 0.35; 'clear': 0.35; 'functions.': 0.35; 'instance': 0.35; 'unit': 0.35; 'created': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'files': 0.38; 'test': 0.39; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'close': 0.61; 'telling': 0.61; 'making': 0.62; 'believe': 0.66; 'skip:\xe2 10': 0.70; 'subjectcharset:utf-8': 0.71; '8bit%:27': 0.72; 'truth': 0.79; '_o__)': 0.84; 'mencken': 0.84; 'received:125': 0.84; '\xe2\x80\x94henry': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100793

Show key headers only | View raw


eryk sun <eryksun@gmail.com> writes:

> On Wed, Dec 23, 2015 at 7:36 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> > So how do I get from a Python 2 ‘file’ object, to whatever
> > ‘io.TextIOWrapper’ wants?
>
> I would dup the file descriptor and close the original file. Then open
> the file descriptor using io.open

Thanks. Okay, now I reveal (I apologise for not making this clear
initially) that I need the *same* code to work with pseudo files created
by the unit test suite: files with no underlying file handle.

That is, I need the same code to accept:

* A Python 2 ‘file’ instance as emitted by many stdlib functions.
* A Python 3 ‘io.*’ file object as emitted by many stdlib functions.
* A pseudo-file (e.g. ‘io.BytesIO’) test double.

With any of those, I need the code to wrap a stream already open in
“binary” mode, and give me a wrapper (e.g. ‘io.TextIOWrapper’) to read
and/or write text on that stream.

-- 
 \     “It is hard to believe that a man is telling the truth when you |
  `\      know that you would lie if you were in his place.” —Henry L. |
_o__)                                                          Mencken |
Ben Finney

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: What interface is a ‘Popen.stdout’ presenting? Ben Finney <ben+python@benfinney.id.au> - 2015-12-24 15:40 +1100

csiph-web