user1462782
user1462782

Reputation: 19

How to convert UTF8 hex to Unicode codepoint in python

I'm making a config file that contains the map of emoji's Unicode and SoftBank Unicode. Now I'm using a python program to scrach this information from http://punchdrunker.github.com/iOSEmoji/table_html/ios6/index.html

but there is a problem , the SoftBank Code on the web page is UTF8 hex, not Unicode codepoint , how to change it to Unicode codePoint?

for example , I want to change EE9095 to E415 (the first emoji emotion)

I try to do it like this , but it just didn't work

code.decode('utf-8')

but it just didn't work, the code is the same, didn't change. the unix command iconv didn't work too

Upvotes: 0

Views: 8771

Answers (2)

plaes
plaes

Reputation: 32746

How about this:

>>> 'EE9095'.decode('hex').decode('utf-8')
<<< u'\ue415'

Upvotes: 4

kennytm
kennytm

Reputation: 523544

Are you sure code is actually encoded in UTF-8? This works for me:

>>> b'\xee\x90\x95'.decode('utf-8')
u'\ue415'

Upvotes: 4

Related Questions