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?

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: What interface is a ‘Popen.stdout’ presenting?
Date 2015-12-24 15:40 +1100
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>

Show all headers | 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