How to emit UTF-8 from console mode?

Mark Tolonen M8R-yfto6h at mailinator.com
Thu Oct 2 04:20:29 CEST 2008


"Ross Ridge" <rridge at csclub.uwaterloo.ca> wrote in message 
news:gc10lj$jqe$1 at rumours.uwaterloo.ca...
>> 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.

It is odd, though, that when the code page (and font) are correct, 
redirecting to a file and typing it work, but printing the result to the 
console does not 




More information about the Python-list mailing list