【发布时间】:2016-08-12 03:42:13
【问题描述】:
我正在尝试将字符串逐个字符转换为十六进制字符,但在 Python3 中我无法弄清楚。
在较旧的 python 版本中,我下面的工作:
test = "This is a test"
for c in range(0, len(test) ):
print( "0x%s"%string_value[i].encode("hex") )
但是使用 python3 我收到以下错误:
LookupError: 'hex' 不是文本编码;使用 codecs.encode() 处理任意编解码器。
谁能帮我告诉我在 python3 中的转换是什么。
提前致谢
【问题讨论】:
标签: python python-3.x