How to emit Cyrillic and Chinese via unicode from console mode?

Gertjan Klein gklein at xs4all.nl
Sun Sep 14 12:51:35 CEST 2008


rs387 wrote:

>sys.stdout = encodings.utf_8.StreamWriter(sys.stdout)
>
>win32console.SetConsoleCP(65001)
>win32console.SetConsoleOutputCP(65001)

[...]

>If redirected to file, all is well, this prints everything properly in
>UTF-8. If ran on the console, this also prints everything correctly,
>but then throws a mysterious exception:

Interesting. On my system (Windows XP) the console codepage does not
change, and hence the characters don't print properly (I get some of the
CP437 line drawing characters, for example). I have never been able to
convince windows to assume/support UTF-8 encoding in the console,
programatically or otherwise. :(

Gertjan.

-- 
Gertjan Klein <gklein at xs4all.nl>



More information about the Python-list mailing list