[Tutor] Re: unichr() question

Ezequiel, Justin j.ezequiel at spitech.com
Fri Oct 17 21:22:51 EDT 2003


>> > >>> 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()?

On Thu, 16 Oct 2003, Terry Carroll wrote:
>> If you have a way of getting a "wide build" I
>> suspect this would do the trick for you.
>> 
>> There's more information in PEP 261, 
>> http://www.python.org/peps/pep-0261.html : I think this is the last word 
>> on it.
>> 
Thanks Terry. I guess I'll just have to live with my eval() workaround.
Thanks also for the link to the PEP. Will re-read it to see if I missed anything.



More information about the Tutor mailing list