problem using array of instances

Anton Muhin antonmuhin at sendmail.ru
Tue Feb 11 04:25:49 EST 2003


zenguyuno at yahoo.com wrote:
> 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
It's almost impossible to understand what is going on. Please, post some 
  actual code.

Anton.





More information about the Python-list mailing list