How do I convert unicode (Chinese characters) into hexadecimal using Python? I have been searching around for few days, but no luck.
Example:
Before convert: 耳环测试
After convert: 8033 73AF 6D4B 8BD5
I get the result using the following unicode online convertor tool: http://r12a.github.io/apps/conversion/
But I didn't manage to get it in my python code.
I tried using "binascii.hexlify(data)" but the result is "e880b3e78eafe6b58be8af95". I didn't manage to get the 4 digits hexadecimal.
my code:
s1 = "耳环测试"
s2 = binascii.hexlify(s1)
print s2 # Result: e880b3e78eafe6b58be8af95
I am using python 2.7 (Google App Engine). How do I convert "e880b3e78eafe6b58be8af95" to "8033 73AF 6D4B 8BD5" ?
Does anyone know how to solve this?
Thank you!
Joel
8033 73AF 6D4B 8BD5
是UTF-16代码点,python为你提供了UTF-8。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.