0

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!

1
  • Can you show us the full code? Commented Sep 30, 2014 at 3:07

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Oops, you're totally right! I changed around my variables earlier and totally forgot. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.