[Tutor] Index Out of Range?List

Steven D'Aprano steve at pearwood.info
Wed May 3 20:32:24 EDT 2017


On Wed, May 03, 2017 at 07:32:53PM -0400, Stephen P. Molnar wrote:

[...]
> When it is run I get:
> 
> IndexError: list index out of range

That alone is useless to us. Please post the full traceback, starting 
from the line 

    Traceback (most recent call last):

Among other things, it will show us the line of code that causes the 
error. Otherwise, we're just guessing.

You might also like to consider a simple debugging technique: print 
the index and the length of the list just before trying to use them. 
E.g. if you want to extract the nth item of a list, write:

    print(n, len(a_list))
    value = a_list[n]


(And yes, I completely agree that the error message should show that 
information, but it currently doesn't.)


-- 
Steve


More information about the Tutor mailing list