Unicode stdin/stdout

Robin Becker robin at reportlab.com
Mon Nov 18 12:47:56 CET 2013

On 15/11/2013 18:16, random832 at fastmail.us wrote:
> Of course, the real solution to this issue is to replace sys.stdout on
> windows with an object that can handle Unicode directly with the
> WriteConsoleW function - the problem there is that it will break code
> that expects to be able to use sys.stdout.buffer for binary I/O. I also
> wasn't able to get the analogous stdin replacement class to work with
> input() in my attempts.
I started to use this on my windows installation

import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
sys.stderr = codecs.getwriter("utf-8")(sys.stderr.detach())

which makes them writable with any unicode; after many years I am quite used to 
garbage appearing in the windows console.

Unfortunately the above doesn't go into virtual environments, but I assume a 
hacked site.py could do that.
Robin Becker

More information about the Python-list mailing list