[issue1602] windows console doesn't print or input Unicode

Giampaolo Rodola' report at bugs.python.org
Sat May 19 20:55:41 CEST 2012


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

Not sure whether a solution has already been proposed because the issue is very long, but I just bumped into this on Windows and come up with this:


from __future__ import print_function
import sys

def safe_print(s):
    try:
        print(s)
    except UnicodeEncodeError:
        if sys.version_info >= (3,):
            print(s.encode('utf8').decode(sys.stdout.encoding))
        else:
            print(s.encode('utf8'))

safe_print(u"\N{EM DASH}")


Couldn't python do the same thing internally?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1602>
_______________________________________


More information about the Python-bugs-list mailing list