【发布时间】:2012-07-08 16:05:13
【问题描述】:
在 Python 2.x 中我可以做到这一点:
>>> '4f6c6567'.decode('hex_codec')
'Oleg'
但是在 Python 3.2 中我遇到了这个错误:
>>> b'4f6c6567'.decode('hex_codec')
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
b'4f6c6567'.decode('hex_codec')
TypeError: decoder did not return a str object (type=bytes)
根据docs hex_codec 应该提供“字节到字节的映射”。所以这里正确使用了byte-string的对象。
我怎样才能摆脱这个错误,以避免从十六进制编码的文本转换为笨拙的解决方法?
【问题讨论】:
标签: python python-3.x codec