Newbie: List of instances?

Jeff Layton laytonjb at bellsouth.net
Fri Mar 29 14:29:31 EST 2002


Hello,

   I'm still learning Python and I'm playing around with some
code that creates a class. I've mastered that stage already.
However, what I want to do is create multiple instances of
the class and put them into a list.
   If the class is called Bob, then I want to do something like,


a = []
a[0] = Bob('input1')


and so on. Everytime I try something like this I get the following
error message:


a[0] = Bob( 'localhost' )
IndexError: list assignment index out of range


   I also tried it this way,


a = []
a.append = Bob('localhost')


and I get the error message:


a[0] = Bob( 'localhost' )
IndexError: list assignment index out of range

   Can anyone shed some light into how I do this? Or is
there a better way?

TIA,

Jeff






More information about the Python-list mailing list