Displaying Unicode on the console (Windows)

Paul Moore gustav at morpheus.demon.co.uk
Mon Apr 14 13:41:29 EDT 2003


Skip Montanaro <skip at pobox.com> writes:

>     Paul> To use a concrete example, I'd like to print the Euro symbol. A
>     Paul> Unicode string for this is u'\20a0'
>
>     >>>> unicodedata.name(u'\u20a0')
>     Paul> 'EURO-CURRENCY SIGN'
>
>     ...
>     >>>> print u'\u20a0'.encode("latin-15")
>     ...
>     >>>> print u'\u20a0'.encode("latin-1")
>     ...
>     >>>> print u'\u20a0'.encode("iso8859_15")
>     ...
>     >>>> print u'\u20a0'.encode("cp1258")
>     ...
>     >>>> print u'\u20a0'.encode("mbcs")
>     ...
>     Paul> [BTW, in case it's relevant - I know it probably is - the output
>     Paul> from "chcp" at the console prompt is "Active code page: 1252"]
>
> Seems that cp1252 is the most likely encoding you didn't try.  What happens
> if you execute
>
>     print u'\u20a0'.encode("cp1252")

Doh. Dumb typo. But no joy with that:

>chcp 1252
Active code page: 1252

>python
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\u20a0'.encode("cp1252")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Apps\Python\lib\encodings\cp1252.py", line 18, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeError: charmap encoding error: character maps to <undefined>

I don't know if this makes me feel better or worse...

Paul.
-- 
This signature intentionally left blank




More information about the Python-list mailing list