How to emit UTF-8 from console mode?

Ross Ridge rridge at csclub.uwaterloo.ca
Wed Oct 1 19:21:23 EDT 2008


> I need UTF-8 because I need to experiment with some OS function calls that 
> give me UTF-16 and I need to emit UTF-16 or UTF-8.

<martin at v.loewis.de> wrote:
>Try setting the code page to 65001, and emit the UTF-8 explicitly.

Hmm... apparently that's not allowed on Windows XP:

C:\> chcp 65001
Active code page: 65001

C:\> python -c "for i in range(0x410, 0x430): print unichr(i).encode('utf-8')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
IOError: [Errno 13] Permission denied

This works though:

C:\> python -c "for i in range(0x410, 0x430): print unichr(i).encode('utf-8')" > x

C:\> type x
[a bunch of Cyrillic letters]

Hmm... "more x" doesn't work, while "copy x con" works but gives an error.
Looks like Windows XP support UTF-8 console output is a bit half-assed.

					Ross Ridge

-- 
 l/  //	  Ross Ridge -- The Great HTMU
[oo][oo]  rridge at csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //	  



More information about the Python-list mailing list