[issue3975] PyTraceBack_Print() doesn't respect # coding: xxx header
STINNER Victor
report at bugs.python.org
Wed Oct 8 12:51:42 CEST 2008
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> More fun will arise when my Windows terminal (encoding=cp1252)
> will try to display Chinese characters. Let's pretend this is
> yet another issue.
I tried the patch using a script with unicode characters (character
not representable in ISO-8859-1 like polish characters ł and Ł).
Result in an UTF-8 terminal (my default locale):
Traceback (most recent call last):
File "unicode.py", line 2, in <module>
raise ValueError("unicode: Łł")
ValueError: unicode: Łł
=> correct
Result in an ISO-8859-1 terminal (I changed the encoding in my Konsole
configuration):
Traceback (most recent call last):
File "unicode.py", line 2, in <module>
raise ValueError("unicode: \u0141\u0142")
ValueError: unicode: \u0141\u0142
=> correct
Why does it work? It's because PyErr_Display() uses sys.stderr instead
of sys.stdout and sys.stderr uses a different unicode error mechanism:
>>> import sys
>>> sys.stdout.errors
'strict'
>>> sys.stderr.errors
'backslashreplace'
Which is a great idea :-)
You can try on Windows using the new attached file unicode.py.
Added file: http://bugs.python.org/file11746/unicode.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3975>
_______________________________________
More information about the Python-bugs-list
mailing list