How to create multiple instances of a class?
Control Reset
control_reset at hotmail.com
Mon Mar 3 07:28:10 EST 2003
Hello,
How do I create multiple instances of a class?
Lets say I have :
class Node():
def __init__(self,index):
print "Index : %d", index
#creat multiple instances
nodes = []
for i in range (10):
nodes[i] = Node(i) <---
The above gives an error, saying something like arrayoutofbounds
array.
Could you please advise.
Which basically boils down to the question on how to use list.
I think nodes = Node(i) will work but I dont want a list in
sequence. Basically what I want is a 2D array which I can access via
an index, eg node[i][j]. How do I do this?
Please advise?
Thank you.
Ctrl-Reset
More information about the Python-list
mailing list