[Tutor] >> BANANAS! << Removing a class instance from a list?

Chris McCormick livelikemad@yahoo.com
Tue, 6 Mar 2001 06:50:04 -0800 (PST)


Hey folx,
  Got a weird one here.  I have a little program to
grow some bananas.  I have a banana class.  It has
methods for maturing at specified intervals,
displaying different bitmaps at different life stages,
and spawning new plants at maturity.
  The program works by creating a list of the class
instances:

bananacount = input('How many bananas do you wanna
see? ')
for x in range(0, bananacount):
    banananame = "banana" + str(x)
    new_banana = flora.Banana(banananame, 0, 0)
    bananas.append(new_banana)

The code above creates the original list.  Then when
bananas get propagated, we append to the list:

def bananaMaker(baby_x, baby_y, banana_name, bananas):
    new_banana = Banana(banana_name, baby_x, baby_y)
    bananas.append(new_banana)

So far, so good, right?  It's easy to append to the
list.  The problem comes when I try to remove items
from the list.  I'm supposed to use the value of the
item I want to remove.  But what is the value of a
class instance?  If I create two bananas and then
print my list, I get something like this:

[<flora.banana instance at 0081168C>, <flora.banana
instance at 0081144C>]

How do I feed that into banana.remove(listitemvalue)?

Thanks in advance for your help.  We're being overrun
here.

- Chris

PS - On the other hand, it's pretty cool to be able to
say that I've crashed my computer with bananas. :-)

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/