View Full Version : quickie python question: "list assignment index out of range"

11 November 2007, 01:53 PM
I've just started learning python, and am porting some old mel scripts over to python, but I've run across a seemingly simple snag!

I want to declare an empty list, and then later on put a value into a specific index...

myArray = []
myArray[0] = "test"

it errors:

# Error: list assignment index out of range
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# IndexError: list assignment index out of range #

It's like the list length is locked - am I missing something obvious here? :D

Any help would be appreciated!

11 November 2007, 02:34 PM
when You initialize any array in python with

myarray = []

it declared the array with zero array members, so first you have to add some array elements,

use like this, for adding elements,

myarray = []

now u can access element myarray[0]

myarray[0] = "newValue"

Vishang Shah

11 November 2007, 02:39 PM
ahh Cheers Vishang! :) :beer:

11 November 2007, 08:21 AM

I have started a blog on python development for CG,

you can check out here,

Happy Developing

Vishang Shah

CGTalk Moderation
11 November 2007, 08:21 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.