Python under PowerShell adds characters

Chris Angelico rosuav at gmail.com
Wed Mar 29 15:29:07 EDT 2017


On Thu, Mar 30, 2017 at 6:13 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> eryk sun <eryksun at gmail.com>:
>> PowerShell is far more invasive. Instead of giving the child process a
>> handle for the file, it gives it a handle for a *pipe*. PowerShell
>> reads from the pipe, and like an annoying busybody that no asked for,
>> decodes the output as text,
>
> You mean, a bit like Python3 does?

If you open a file in Python 3, you can choose whether to open it as
text or binary. When you print text to stdout, well, it's text, so of
course it has to be encoded appropriately; if you're doing something
unusual (like a CGI script creating an image file), you can override
the default and change stdout to be binary. But normally, the standard
streams are connected ultimately to a human, so they're text.

The problem is that PS is decoding and then re-encoding instead of
simply telling the process what encoding to use. That's just wrong.

ChrisA



More information about the Python-list mailing list