[Python-ideas] changing sys.stdout encoding

Chris Rebert pyideas at rebertia.com
Wed Jun 6 08:32:24 CEST 2012


On Tue, Jun 5, 2012 at 11:14 PM, Rurpy <rurpy at yahoo.com> 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 at public.gmane.org> wrote:
<snip>
>> Before adding yet-another-command-line-option, the cases where the
>> existing environment variable support can't be used from the command
>> line, but a new option could be, should be clearly enumerated.
>>
>> $ python3
>> Python 3.2.1 (default, Jul 11 2011, 18:54:42)
>> [GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import sys
>>>>> sys.stdout.encoding
>> 'UTF-8'
>>>>>
>> $ PYTHONIOENCODING=latin-1 python3
>> Python 3.2.1 (default, Jul 11 2011, 18:54:42)
>> [GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import sys
>>>>> sys.stdout.encoding
>> 'latin-1'
>
> 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.

Cheers,
Chris



More information about the Python-ideas mailing list