如何将'dead'
字符串转换为 unicode 字符串u'\xde\xad'
?
这样做:
from binascii import unhexlify
out = ''.join(x for x in [unhexlify('de'), unhexlify('ad')])
创建一个<type 'str'>
字符串'\xde\xad'
尝试像这样使用 Unicode.join() :
from binascii import unhexlify
out = ''.join(x for x in [u'', unhexlify('de'), unhexlify('ad')])
导致错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xde in position 0: ordinal not in range(128)