[issue5110] Printing Unicode chars from the interpreter in a non-UTF8 terminal (Py3)

STINNER Victor report at bugs.python.org
Fri Jan 30 16:46:51 CET 2009


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

You change change the display hook with a site.py script (which have 
to be in sys.path) :
---------
import sys

def hook(message):
    print(ascii(message))

sys.displayhook = hook
---------

Example (run python in an empty environment to get ASCII charset):
---------
$ env -i PYTHONPATH=$PWD ./python
Python 3.1a0 (py3k:69105M, Jan 30 2009, 10:36:27)
>>> import sys
>>> sys.stdout.encoding
'ANSI_X3.4-1968'
>>> "\xe9"
'\xe9'
>>> print("\xe9")
Traceback (most recent call last):
  (...)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' (...)
---------

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


More information about the Python-bugs-list mailing list