[Python-ideas] Subprocess: Add an encoding argument
Terry Reedy
tjreedy at udel.edu
Tue Sep 2 23:29:32 CEST 2014
On 9/2/2014 9:25 AM, Nick Coghlan wrote:
> On 2 September 2014 07:15, Paul Moore <p.f.moore at gmail.com> wrote:
>> The find -print0 example is out of scope, IMO, as newline handling is
>> different from encoding. At some point, it becomes easier to manually
>> wrap the streams rather than having huge numbers of parameters to the
>> Popen constructor.
>
> Don't forget Antoine's suggestion of creating a TextPopen subclass
I would expect something call Textxxx to present with (text) strings,
not bytes.
> that wraps the streams as strict UTF-8 by default and allows the
But this implies to me that I would still get (encoded) bytes.
> encoding and errors arguments to be either strings (affecting all
> pipes) or a dictionary mapping "stdin", "stdout" and "stderr" to
> individual settings.
What I would want is automatic conversion of strings to encoded bytes on
send to the pipe and automatic reconersion of encoded bytes to strings
on received. For that, there is little reason I can think of to use
anything other than utf-8
> With that, the simple utf-8 example just becomes:
>
> with TextPopen(cmd, stdout=PIPE) as p:
> for line in p.stdout:
> process(line)
Would type(line) be str or bytes?
--
Terry Jan Reedy
More information about the Python-ideas
mailing list