How to emit UTF-8 from console mode?

"Martin v. Löwis" martin at v.loewis.de
Wed Oct 1 01:53:42 EDT 2008


> LC_CTYPE=en_US.UTF-8 urxvt-X.exe&
> perl -wle "binmode STDOUT, q[:utf8]; print chr() for 0x410 .. 0x430;"

> Can someone help me translate it into python?

LC_CTYPE=en_US.UTF-8 urxvt-X.exe&
python -c 'for i in range(0x410, 0x431):print unichr(i),'

> I would not expect it to work 
> from cmd.exe with python

It should work in cmd.exe, as long as the terminal's encoding supports
these characters in the first place. Use chcp.exe to find out what the
terminal's encoding is. The Python program is not completely equivalent,
as it leaves the output encoding to Python, rather than assuming a fixed
UTF-8 output encoding.

Regards,
Martin




More information about the Python-list mailing list