[Tutor] unichr() question

Ezequiel, Justin j.ezequiel at spitech.com
Mon Oct 13 22:45:15 EDT 2003


PythonWin 2.2.2
Windows XP

>>> long('1D4AA', 16)
119978L
>>> unichr(long('1D4AA', 16))
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
>>> x = eval("u'\\U000%s'" % '1D4AA')
>>> x
u'\U0001d4aa'
>>> for c in x:
... 	print ord(c)
... 
55349
56490
>>> unichr(55349) + unichr(56490)
u'\U0001d4aa'
>>> 

How do I convert strings such as '1D4AA' to unicode without using eval()?
Alternatively, how can I break down the value 119978L into 55349 and 56490?



More information about the Tutor mailing list