[Python-ideas] Unicode stdin/stdout

Nick Coghlan ncoghlan at gmail.com
Mon Nov 18 07:59:16 EST 2013


On 18 Nov 2013 22:36, "Robin Becker" <robin at reportlab.com> wrote:
>
> On 18/11/2013 11:47, Robin Becker wrote:
> ...........
>>
>> #c:\python33\lib\site-packages\sitecustomize.py
>> import sys, codecs
>> sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
>> sys.stderr = codecs.getwriter("utf-8")(sys.stderr.detach())
>
> ........
> it seems that the above needs extra stuff to make some distutils logging
work etc etc; so now I'm using sitecustomize.py containing
>
> import sys, codecs
> sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
> sys.stdout.encoding = 'utf8'
> sys.stderr = codecs.getwriter("utf-8")(sys.stderr.detach())
> sys.stderr.encoding = 'utf8'

Note that calling detach() on the standard streams isn't officially
supported, since it breaks the shadow streams saved in sys.__stderr__, etc.

Cheers,
Nick.

>
> --
> Robin Becker
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131118/04fd4913/attachment.html>


More information about the Python-list mailing list