Reputation: 9
I keep getting the following error:
Traceback (most recent call last):
File "G:\Data\Box Sync\Box Sync\run9.py", line 122, in <module>
print "%11s %11s %10.f %17.f %1.2f %7.f %2.2f %2.2f %2.2f" %(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8])
IndexError: tuple index out of range
I have tested all the lines previous and they are working fine. I get that the tuples are out of range when I have added i[6] and subsequent parts in the if I try to remove them then I get that there enough arguments for format string; which makes sense. What I cannot figure out is why the tuple out of range error is coming from. suggestions?
for i in range(n):
for j in range(n):
if j > i:
flydrivelist.append((P[i][0], P[j][0], D[i][j], E[i][j], R[i][j], D[i][j]-E[i][j], round(D[i][j] / drive, 2), round(E[i][j] / fly, 2), round((D[i][j] / drive) / (E[i][j] / fly), 2) ))
#print flydrivelist this was used to test values; they are coming out correctly...
for i in sortedlist:
print "%11s %11s %10.f %17.f %21.2f %7.f %2.2f %2.2f %2.2f" %(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8])
Upvotes: 0
Views: 40
Reputation: 362627
This means your object i
is a tuple and it has less than 9 elements. It's an error message raised from tuple.__getitem__
:
>>> ('a', 'b')[3]
IndexError: tuple index out of range
If you used the normal method of %-formatting, i.e. putting the tuple itself, you would see a different (and probably more useful) error message:
>>> '%s %s %s' % (0, 1)
TypeError: not enough arguments for format string
Upvotes: 1