我試圖將一個時間值存儲在一個數組中,但每次都會給我一個錯誤,即使我嘗試將float轉換爲int也是如此。這裏是我的代碼的部分:強制轉換爲int而不能在Python中工作
EndTimes = [0,0,0,0]
...
EndTimes[TakenSlots] = int(time.time() + n)
,但它只是給出了這樣的錯誤:
[error] TypeError (list indices must be integers)
[error] --- Traceback --- error source first
line: module (function) statement
44: main (craftTime) EndTimes[TakenSlots] = tempInt
我想這個代碼只是爲了看看它認爲的價值是:
tempInt = int(time.time() + n)
print tempInt
EndTimes[TakenSlots] = tempInt
它只是輸出1412046180(沒有小數位,這似乎應該是一個int)
有誰知道w帽子發生了嗎?它是int()還是我使用的數組類型的問題?提前致謝!
您能告訴我們完整的代碼嗎? – 2014-09-30 03:07:08