boativan66
boativan66

Reputation: 23

How to convert an accented character in an unicode string to its unicode character code using Python?

Just wonder how to convert a unicode string like u'é' to its unicode character code u'\xe9'?

Upvotes: 2

Views: 1007

Answers (3)

unbeknown
unbeknown

Reputation:

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

>>> u'é' == u'\xe9'
True

Upvotes: 1

Peter Milley
Peter Milley

Reputation: 2808

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

>>> ord(u'é')
233

Upvotes: 1

Andrew
Andrew

Reputation: 13191

You can use Python's repr() function:

>>> unicode_char = u'é'
>>> repr(unicode_char)
"u'\\xe9'"

Upvotes: 3

Related Questions