[英]In Python, how to convert a hexadecimal number to its corresponding unicode character?
[英]Python - How to convert unicode to hexadecimal
如何使用Python將unicode(中文字符)轉換為十六進制? 我一直在尋找幾天,但沒有運氣。
例:
轉換前:耳環測試
轉換后:8033 73AF 6D4B 8BD5
我使用以下unicode在線轉換器工具獲得結果: http : //r12a.github.io/apps/conversion/
但我沒有設法在我的python代碼中得到它。
我嘗試使用“binascii.hexlify(data)”,但結果是“e880b3e78eafe6b58be8af95”。 我沒有設法得到4位十六進制數。
我的代碼:
s1 = "耳環測試"
s2 = binascii.hexlify(s1)
print s2 # Result: e880b3e78eafe6b58be8af95
我使用的是python 2.7(Google App Engine)。 我怎么把“e880b3e78eafe6b58be8af95”改為“8033 73AF 6D4B 8BD5”?
有誰知道如何解決這個問題?
謝謝!
喬爾
8033 73AF 6D4B 8BD5
是UTF-16代碼點,python為你提供了UTF-8。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.