IDLE and Unicode characters (2.5.4)

Why does IDLE handle one character correctly but not another?

>>> e = '€'
>>> print unichr(ord(e))
     # looks like a very thin rectangle on my system.
>>> p = '£'
>>> print unichr(ord(p))
£
>>> ord(e)
128
>>> ord(p)
163

I tried adding various # coding lines, but that didn't help.

EDIT: The browser must be UTF-8, otherwise it will look rather strange.

EDIT 2: On my system, the euro char displays correctly on line 1, but not on the print line. Pound char displays correctly in both places.

+3
source share
2 answers

The answer depends on what encoding IDLE REPL uses. You should be more clear about what the text is in Unicode, and what a byte sequence is. Reflect on this example:

# -*- coding: utf-8 -*-
c = u'€'
print type(c)
for b in c.encode('utf-8'):
    print ord(b)

c = '€'
print type(c)
for b in c:
    print ord(b)

EDIT:

IDLE, borken, .

IDLE 1.2.2      
>>> c = u'€'
>>> ord(c)
128
>>> c.encode('utf-8')
'\xc2\x80'
>>> c
u'\x80'
>>> print c
[the box thingy]


>>> c = u'\u20ac'
>>> ord(c)
8364
>>> c.encode('utf-8')
'\xe2\x82\xac'
>>> c
u'\u20ac'
>>> print c

, €, .

+3

, , . , IDLE ui. , , (, Arial Unicode ).

, , -.

0

Source: https://habr.com/ru/post/1721299/


All Articles