[Tutor] Index out of range

Jacob S. keridee at jayco.net
Mon Oct 18 04:18:25 CEST 2004


I know your what your problem is!

You started you col referencing with 1.
Python starts indexing at 0.  For example.

>>> a = [1,2,3,4,1,5]
>>> a[0]
1
>>> a[5]
5
>>> a[6]
Traceback (most recent call last):
    File "<stdin>", line 1, in ?
IndexError: list index out of range
>>>

Your script goes from col[1] to col[71]. col[71] is not recognized because
it actually references item 72, which doesn't exist.

I agree with Kent Johnson, it would be a lot easier to use the join function
than to write out all of those list references.

>
>"insert into table "+tname+" values('" + "', '".join(col) + "')"
>

HTH,

Jacob Schmidt



More information about the Tutor mailing list