Unicode stdin/stdout

Robin Becker robin at reportlab.com
Mon Nov 18 17:08:56 CET 2013

On 18/11/2013 15:25, Victor Stinner wrote:
> Why do you need to force the UTF-8 encoding? Your locale is not
> correctly configured?
> It's better to set PYTHONIOENCODING rather than replacing
> sys.stdout/stderr at runtime.
> There is an open issue to add a TextIOWrapper.set_encoding() method:
> http://bugs.python.org/issue15216
> Victor
well reportlab does all sorts of character sets and languages; if I put in a 
quick print to try and debug stuff I prefer that it create some output rather 
than create an error of its own. In the real world it's not possible always to 
know what the output contains (especially in error cases) so having any 
restriction on the allowed textual outputs is a bit constraining.

The utf8 encoding should allow any unicode to be properly encoded, rendering is 
another issue and I expect some garbage when things are going wrong.

I think you are right and I should use PYTHONIOENCODING to set this up. In the 
codec writer approach I think it's harder to get interactive behaviour working 
properly (the output seems to be buffered differently). My attempts to make 
windows xp use code page 65001 everywhere have been fairly catastrophic eg 
non-booting :(
Robin Becker

More information about the Python-list mailing list