[Python-3000] encode function errors="replace", but print() failed, is this a bug?
"Martin v. Lo"wis"
martin at v.loewis.de
Thu Nov 20 07:45:41 CET 2008
> Am I using it in a wrong way or is it a bug?
You are using it in a wrong way. The terminal window, on Windows, does
not use the "mbcs" encoding. Microsoft has two system encodings: the
"ANSI" code page (CP_ACP), called "mbcs" by Python, and the "OEM" code
page (CP_OEMCP). The latter is what the terminal window uses. Python
does not directly expose the Microsoft OEMCP codec; instead, it
determines the terminal's code page, and then carries its own codec for
that code page ("gbk" in your case).
To make your example work, replace "mbcs" with sys.stdout.encoding.
HTH,
Martin
More information about the Python-3000
mailing list