我得到一个由 struct.pack
打包的字符串,我需要解压缩它。我原来的python2代码是这样的:
import struct
# an example of input x is '\x82\xf6\x1e\x00\xe86*?\xf6\xd3#\x00\xc4\xb8&?\xff\xd6"\x00T,\xc3>'
# I wonder how to get b'\x82\xf6\x1e\x00\xe86*?\xf6\xd3#\x00\xc4\xb8&?\xff\xd6"\x00T,\xc3>'
def MyUnpack(x):
value = bytes(x)
print(struct.unpack("If" * (len(value) // 8), bytes(value)))
现在我想把它转换成python3。
我尝试过 2to3
,但它什么也没做。
我尝试了 bytes(value, encoding='ascii')
和 value = x.encode()
,但都不起作用。