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

Python struct.error:必需的参数不是整数,python,python-3.x,Python,Python 3.x,我有以下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.erro

我有以下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
您正在为传入的参数使用:
h
格式表示存储
short
,而传入的值,即
vr
vl
,看起来像
double
s


考虑将它们键入
int
或使用
>Bdd“
格式。

什么是
self
?代码中没有定义它。特别是,
self.callbackKeyUp
self.callbackKeyDown
self.callbackKeyLeft
self.callbackKeyRight
的值是什么?您应该确定这些值是什么,然后修改示例代码,使其不引用
self
。增量和减量是复制所必需的吗?我为您简化了它,@jpmc26,因为您请求:)