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


Groups > comp.lang.python > #100793 > unrolled thread

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

Started byBen Finney <ben+python@benfinney.id.au>
First post2015-12-24 15:40 +1100
Last post2015-12-24 15:40 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromBen Finney <ben+python@benfinney.id.au>
Date2015-12-24 15:40 +1100
SubjectRe: What interface is a ‘Popen.stdout’ presenting?
Message-ID<mailman.102.1450932021.2237.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web