如何将python2“字节”函数转换为python3代码?

时间:2021-02-25 14:43:49

标签: python python-3.x python-2.7 byte

我得到一个由 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(),但都不起作用。

0 个答案:

没有答案
相关问题