Issue
I'm trying to store a time value in an array, but it gives me an error every time, even when I try to cast the float into an int. Here is the portion of my code:
EndTimes = [0,0,0,0]
...
EndTimes[TakenSlots] = int(time.time() + n)
But it just gives this error:
[error] TypeError ( list indices must be integers )
[error] --- Traceback --- error source first
line: module ( function ) statement
44: main ( craftTime ) EndTimes[TakenSlots] = tempInt
I tried this code just to see what it thought the value was:
tempInt = int(time.time() + n)
print tempInt
EndTimes[TakenSlots] = tempInt
And it just outputted 1412046180 (no decimal places, which seems like it should be an int)
Does anyone know what's happening? Is it a problem with the int() or the type of array I'm using? Thanks in advance!
Solution
This occurs because the list index ( list[index] = value ) must be an integer. It is probable that TakenSlots is not an int.
>>> l = [1,2,3]
>>> l[1.3] = 10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not float
Answered By - Kknd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.