[Python-ideas] Subprocess: Add an encoding argument

Akira Li 4kir4.1i at gmail.com
Mon Sep 1 22:53:42 CEST 2014


Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> writes:

> On Monday, September 1, 2014 1:10 PM, Akira Li <4kir4.1i at gmail.com> wrote:
>
>>Paul Moore <p.f.moore at gmail.com> writes:
>>
>>> On 1 September 2014 20:14, Akira Li
>>> <4kir4.1i at gmail.com> wrote:
>>>> Could you provide examples how the final result could look like?
>>>
>>> Do you mean what I'm proposing?
>>>
>>> p = Popen(..., encoding='utf-8')
>>> p.stdout is now a text stream assuming the data is in UTF8, rather
>>> than assuming it's in the default encoding.
>>
>>What if you want to specify an error handler e.g., to read a file list
>>from `find -print0` -like program: you could pass
>>errors='surrogateescape', newlines='\0' (issue1152248) to
>>TextIOWrapper(p.stdin).
>
> Presumably you either meant passing them to `TextIOWrapper(p.stdout)`
> for `find -print0`, or passing them to `TextIOWrapper(p.stdin)` for
> xargs -0`; find doesn't even look at its input.
>

You are right. I've looked at 'surrogateescape' that means reading, that
is associated with sys.stdin; so I wrote p.stdin instead of p.stdout by
mistake.


--
Akira



More information about the Python-ideas mailing list