2015-09-06 479 views
2

,我有以下的Python代碼..struct.error:需要的參數不是整數

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

什麼是「自我」?它沒有在代碼中的任何地方定義。特別是'self.callbackKeyUp','self.callbackKeyDown','self.callbackKeyLeft'和'self.callbackKeyRight'的值是什麼?你應該確定這些值是什麼,然後修改示例代碼,以便它不引用「self」。增量和減量是否需要重現? – jpmc26

+1

我讓你更簡單,@ jpmc26因爲你要求:) – C0NFUS3D

回答

1

您正在使用incorrect formats的參數您傳遞:h格式表示存儲short,而您傳入​​的值,即vrvl,看起來像double s。

考慮將它們類型化爲int或使用">Bdd"格式。