Dave wrote: > class A(object): > def create_child(self): > self.child = B() > self.child.do_stuff(self) > > class B(object): > def do_stuff(self, parent): > self.parent = parent > if self.parent.__class__.__name__ == 'A': > print "I'm a child of an A!" > else: > print "Well, I'm a motherless child. Does that mean I can > kill Macbeth?"
Depending on your actual needs you could change that to: class A(object): def create_child(self): self.child = B(self) class B(object): def __init__(self, parent): self.do_stuff(parent) def do_stuff(self, parent): self.parent = parent if self.parent.__class__.__name__ == 'A': print "I'm a child of an A!" else: print "I know ye not!" which IMHO makes it clearer from A's perspective. --eric -- http://mail.python.org/mailman/listinfo/python-list