gpt4 book ai didi

python - python中使用Struct打包128字节结构出错

转载 作者:行者123 更新时间:2023-12-01 07:03:07 25 4
gpt4 key购买 nike

我想打包128字节的不同数据类型。结构如下

4 字节 - 0x12345678,

2 字节 - 0x1234,

120 字节 - 0x00(重复 120 次),

2 字节 - 0x99,

我尝试使用以下代码但失败

struct.pack('<LH120BH',0x12345678,0x1234,0x00,0x99 )

报错

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
struct.pack('<LH120BH',0x12345678,0x1234,0x00,0x99 )
struct.error: pack expected 123 items for packing (got 4)

请帮助我。在此先感谢

最佳答案

如果你想让 0x00 重复 120 次,你可能需要将它打包到一个数组中,并在调用 struct.pack 时解压它,也许是这样的:

struct.pack('<LH120BH',0x12345678,0x1234,*[0x00] * 120,0x99)

关于python - python中使用Struct打包128字节结构出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58555670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com