Setting stdout encoding

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Sep 14 00:06:11 EDT 2007


En Thu, 13 Sep 2007 08:08:39 -0300, Fabio Zadrozny <fabiofz at gmail.com>  
escribi�:

>>
>> But I don't think it's a good idea. Changing the default encoding will
>> change it for *all* scripts, *all* users, *all* objects. And AFAIK you
>> have trouble ONLY with sys.std* - one should fix those objects, not mess
>> with a global configuration.
>>
>
> Makes sense... Do you think that creating a new object, setting it as
> sys.stdout and overriding its write() method to check for a unicode  
> string
> to do original_stdout.write(unicode_str.encode(my_encoding)) would do it?

Yes. See the other message from Ryan Ginstrom.

> (the ctypes version is not really an option as it is not available on  
> lots
> of installs -- although I can try to use it if it's available, but it  
> can't
> be the only solution).

I see... Wrapping stdout with your own object seems reasonable then.

-- 
Gabriel Genellina




More information about the Python-list mailing list