Non-ascii characters in an MSDOS window
Martin v. Löwis
loewis at informatik.hu-berlin.de
Fri Oct 18 11:15:02 CEST 2002
"Bartolomé Sintes Marco" <BartolomeSintes at ono.com> writes:
> I understand that Python is not to "blame", but Windows. So,
> is it not possible to have the same output in a command line windows
> and in a GUI window?
Difficult. http://python.org/sf/612627 is a patch that makes
sys.stdout accept Unicode strings on printing, and converts it into
the encoding of the terminal.
At the moment, you have the following options:
A. Change the code page in the console with the chcp.exe. This requires to set
the console font to Lucida Console (or another Unicode font).
B. Always use Unicode to represent strings with accented
characters. On printing them, determine the encoding of the output
if sys.stdout.isatty() and isinstance(sys.stdout,file):
# console. Unfortunately, there is no way to find out the encoding of
# the console. You could try to parse the output of chcp.
encoding = "cp850"
encoding = "mbcs"
Then encode the string with encoding, and put it onto sys.stdout.
More information about the Python-list