Displaying Unicode on the console (Windows)

Gilles Lenfant glenfant at NOSPAM.bigfoot.com
Mon Apr 14 15:03:40 EDT 2003


"Paul Moore" <gustav at morpheus.demon.co.uk> a écrit dans le message de news:
vfxhrn7a.fsf at morpheus.demon.co.uk...
> Skip Montanaro <skip at pobox.com> writes:
>
> >     ...
> >     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>
>

Anyway, the console glyphs collection used when typing "chcp 1252" is buggy.
The Euro symbol has the code 128 in cp1252 encoding. When typing Alt+0128 in
a console after setting "chcp 1252" writes an upper "ç".
When writing a chr(128) to a file and then viewing it through an editor
shows the Euro symbol...

--Gilles





More information about the Python-list mailing list