[Python-ideas] changing sys.stdout encoding

Rurpy rurpy at yahoo.com
Wed Jun 6 09:36:39 CEST 2012

On 06/06/2012 12:32 AM, Chris Rebert wrote:
> On Tue, Jun 5, 2012 at 11:14 PM, Rurpy <rurpy-/E1597aS9LQAvxtiuMwx3w at public.gmane.org> wrote:
>> On 06/05/2012 11:49 PM, Nick Coghlan wrote:
>>> On Wed, Jun 6, 2012 at 1:28 PM, Stephen J. Turnbull <stephen-Sn97VrDLz2sdnm+yROfE0A-XMD5yJDbdMReXY1tMh2IBg at public.gmane.org> wrote:
>>> $ PYTHONIOENCODING=latin-1 python3
>> I don't think that works on Windows.
> You just need to use the "set" command/built-in
> (http://ss64.com/nt/set.html ; or the PowerShell equivalent) to set
> the environment variable. It's 1 extra line. Blame Windows for not
> being POSIXy enough.

There's a lot more than that I blame Windows for. :-)

There's another extra line to restore the environment to
its original setting too.  And when you forget to do that
remember to straighten out the output of the next python 
program you run.

Also, does not PYTHONIOENCODING affect all three streams?
That would rule it out of consideration in my use case.

But even if not, I'm sorry, compared with running a single 
command with an encoding option, I think messing with 
environment variables is not really a workable solution.  
About the closest I see to do this in practice would be 
to wrap each python program up in a .bat script.

This is really case of the Python tail wagging the 
application dog.

More information about the Python-ideas mailing list