Unicode

Thomas Heller theller at ctypes.org
Fri Mar 15 07:43:49 EDT 2013


Am 15.03.2013 11:58, schrieb Steven D'Aprano:
> On Fri, 15 Mar 2013 11:46:36 +0100, Thomas Heller wrote:
[Windows: Problems with unicode output to console]

> You can isolate the error by noting that the second one only raises an
> exception when you try to print it. That suggests that the problem is
> that it contains a character which is not defined in your terminal's
> codepage. So let's inspect the strings more carefully:
>
>
> py> a = u"µm"
> py> b = u"\u03bcm"
> py> a == b
> False
> py> ord(a[0]), ord(b[0])
> (181, 956)
> py> import unicodedata
> py> unicodedata.name(a[0])
> 'MICRO SIGN'
> py> unicodedata.name(b[0])
> 'GREEK SMALL LETTER MU'
>
> Does codepage 850 include Greek Small Letter Mu? The evidence suggests it
> does not.
>
> If you can, you should set the terminal's encoding to UTF-8. That will
> avoid this sort of problem.

Thanks for the clarification.

For the archives: Setting the console codepage to 65001 and the font to 
lucida console helps.

Thomas




More information about the Python-list mailing list