Avatar ·

How to output a Unicode string to Windows console from Python?

📁 python

Simple print() doesn't work. The interpreter crashes with a complaint that it cannot convert Unicode to the encoding used in the Windows console. Maybe there is a way to help it? Perhaps there is some module that can do this.

Avatar ·

"

Update: uses Unicode API for console input/output as the package mentioned below (more details in ). Arbitrary Unicode characters are supported by default. Simple print(unicode_string) now works without installing additional software (console font supporting the desired characters still needs to be configured).

Unicode is used at the boundary with the Windows console, internally sys.stdin, sys.stdout, sys.stderr use utf-8 encoding. This may break code that used a binary interface for console output and accordingly used OEM codepage, for example cp866 encoding. cp866 is not compatible with utf-8. It is necessary to either fix the code so that it outputs text rather than bytes to the console.

Log in to leave an answer

Blogs