Python如何将unicode转换为hexadecim

2024-03-28 18:30:47 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用Python将unicode(中文字符)转换为十六进制?我已经找了几天了,但没找到。在

示例:

Before convert: 耳环测试

After convert: 8033 73AF 6D4B 8BD5

我使用以下unicode联机转换器工具得到结果: http://r12a.github.io/apps/conversion/

但我没能在python代码中找到它。在

我试着用比纳西伊·赫克斯利菲(数据),但结果是“e880b3e78eafe6b58be8af95”。我没能得到4位数的十六进制数。在

我的代码:

s1 = "耳环测试"
s2 = binascii.hexlify(s1)
print s2 # Result: e880b3e78eafe6b58be8af95

我使用的是python2.7(googleappengine)。如何将“e880b3e78eafe6b58be8af95”转换为“8033 73AF 6D4B 8BD5”?在

有人知道怎么解决这个问题吗?在

谢谢你!在

乔尔


Tags: 工具代码http示例convertunicode联机字符