Partially unpacking a sequence

Fredrik Lundh fredrik at pythonware.com
Fri Apr 7 02:39:13 EDT 2006


tkpmep at hotmail.com wrote:

> Thank you, everyone, for resolving my question. At one point, while
> trying to solve the problem, I typed
>
> >>> y[1,3]
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: list indices must be integers
>
> The error message gave me no clue as to what I was doing wrong (in my
> mind, I was just writing out the elements of a range), and I thought
> perhaps that my inclusion of a comma was the problem. Perhaps a more
> explicit error message would have helped.

the problem is that the *compiler* doesn't know what "y" is, and y[1,3]
is a perfectly valid way to access e.g. a dictionary or a multidimensional
array.  so it's the list implementation that has to do the complaining, and
all it knows is that it wants an integer index, and got something else.

maybe something like

    TypeError: list indices must be integers (got tuple)

would have been less confusing; feel free to add a suggestion to the bug
tracker:

    http://sourceforge.net/tracker/?group_id=5470&atid=105470

</F>






More information about the Python-list mailing list