[Tutor] Write array to Status text

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Nov 18 17:05:40 EST 2003

On Tue, 18 Nov 2003, Vicki Stanfield wrote:

> I have another array (list) which is supposed to hold 3 two digit values.
> I initialized it like this:
> bytearray=[0] * int(parameters[2])
> where parameters[2] is an ascii 3. Evidently this is wrong since I get
> this message when I try to run it:
> IndexError: list index out of range

Hi Vicki,

[Please continue to send your replies to 'tutor at python.org', and not just
me directly.  You need to give the others on the Tutor list the
opportunity to help answer your questions; otherwise, everyone will feel
left out!]

To diagnose this more accurately, we'll probably need to see the full
error traceback to figure out what's happening, stack trace and all.  For
the moment, I have to assume that the traceback message is applying to the

    bytearray=[0] * int(parameters[2])

but if this assumption is incorrect, you need to point that out to us.

An IndexError occurs whenever we try to access beyond the length of our
list.  My initial guess is that, if the error is being emitted from:

    bytearray = [0] * int(parameters[2])

then since 'parameters[2]' is the only subexpression in there that's doing
an indexing operation, the parameter list probably doesn't have three
elements in it.

How are you sure you have at least three elements in that 'parameters'
list?  What happens if you hardcode the value '3' in there, like:

    bytearray = [0] * 3

Let's see if we can isolate this problem.

Good luck to you!

More information about the Tutor mailing list