struct.error:必需参数不是整数

2024-06-16 12:00:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下python代码:

velocity = 0
rotation = 0
vr = velocity + (rotation/2)
vl = velocity - (rotation/2)
cmd = struct.pack(">Bhh", 145, vr, vl)

我处理以下错误:

File "control.py", line 125, in __init__  
cmd = struct.pack(">Bhh", 145, vr, vl)  
struct.error: required argument is not an integer

Tags: 代码inpycmd错误linestructpack
1条回答
网友
1楼 · 发布于 2024-06-16 12:00:11

您使用incorrect formats作为传入的参数:h格式表示存储short,而传入的值,即vrvl,看起来像doubles

考虑将它们类型转换为int或使用">Bdd"格式。

相关问题 更多 >