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

发布于 2021-01-29 16:42:09

我有以下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
关注者
0
被浏览
220
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    您为传入的参数使用了错误的格式hformat表示要存储的short,而传入的值(即vrvl)看起来像doubles。

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



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看