Displaying Unicode Chars

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Sun Feb 10 23:32:22 CET 2008


gregpinero at gmail.com wrote:

> However how can I change it so it works with a string variable?
>
> print unicode("\u221E") doesn't seem to do it.

Sure, that's because \u only works in unicode strings. You'd need
to "encode" your \u-containing string to a unicode string. Perhaps
this'll help:

>>> def to_unicode(num):
...     character = "\\u"+num
...     return character.decode("unicode-escape")
... 
>>> to_unicode("221E")
u'\u221e'
>>> print to_unicode("221E")
∞

(improvements welcome)

Regards,


Björn

-- 
BOFH excuse #273:

The cord jumped over and hit the power switch.




More information about the Python-list mailing list