Newbie: List of instances?

Peter Hansen peter at engcorp.com
Fri Mar 29 17:01:06 EST 2002


Jeff Layton wrote:
> 
> > a.append(Bob('localhost'))
> 
> This works! If I create a list a that has five elements where
> are just instances of Bob, can I "call" a method for a specific
> element of the list? I take I can (Jeff sneaks off to experiment
> while his wife is napping).

Not sure if you mean can you call a method to get a specific
element of the list (for that you'd just use brackets: a[2]
returns the third element), or whether you mean can you take
a specific instance and call a method on it: a[2].getHost()
for example... the answer in both cases is, of course,
yes you can. :-)

-Peter



More information about the Python-list mailing list