> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Adrian Wood > Sent: Thursday, January 10, 2008 4:47 PM > To: python-list@python.org > Subject: Newbie question on Classes > > > I can call man.state() and then woman.state() or Person.state(man) and > Person.state(woman) to print the status of each. This takes time and > space however, and becomes unmanageable if we start talking about a > large number of objects, and unworkable if there is an unknown number. > What I'm after is a way to call the status of every instance of Man, > without knowing their exact names or number. >
How about searching the garbage collector? import gc from random import random class Person: def __init__(self): self.data= random() * 1000 + 1 def WhoAmI(self): return self.data a = Person() b = Person() for i in gc.get_objects(): try: # classes have __class__ and __dict__ defined according to the docs if i.__class__ and i.__dict__ : print i.__class__ if str(i.__class__) == '__main__.Person': print "\tI am", i.WhoAmI() except: pass ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622 -- http://mail.python.org/mailman/listinfo/python-list