problem using array of instances
zenguyuno at yahoo.com
zenguyuno at yahoo.com
Mon Feb 10 23:50:06 EST 2003
I'm stuck on this one:
I defined a class, call it boat.
I created a list of instances, call it pop, so pop[i] is an instance of
the boat class, and I made pop[0], pop[1], etc., all boats.
The boat class has a method defined, call it go().
I want to define a function and pass i to it. Then inside the function
I want it to call the go() method of the ith boat, like pop[i].next.
This didn't work; Python thinks that pop[i] is an int, and doesn't have
a go() method.
I tried passing pop[i] to the function, so it would know that pop[i] was
a boat, but that didn't work either. (same error)
pop, the list of boats, is global. I put a global statement in the
function.
I'm using Python 2.2 with Windows 98.
Thanks
z
More information about the Python-list
mailing list