views:

104

answers:

3

Just wonder how to convert a unicode string like u'é' to its unicode character code u'\xe9'? Thank you for your help.

+1  A: 

You can use Python's repr() function:

>>> unicode_char = u'é'
>>> repr(unicode_char)
"u'\\xe9'"
Andrew
+1  A: 

ord will give you the numeric value, but you'll have to convert it into hex:

>>> ord(u'é')
233
Peter Milley
+1  A: 

u'é' and u'\xe9' are exactly the same, they are just different representations:

>>> u'é' == u'\xe9'
True
unbeknown
The expression evaluate to True in python but False in ipython. Any reason why that happens? Thank you!
boativan66