On Mon, Jun 23, 2008 at 12:17 AM, John Gunderman <[EMAIL PROTECTED]> wrote: > I am looking for a way to tell a object the properties of its containing > object. > For example, I have an object foo, of class Bar, which I have stored in a > dict > in the object I want to access. Basically: > > container_object.contained_object["foo"].action() > > What I want is for the object "foo" to be able to access properties of > container_object > through its action() method.
Maybe the actions can be bound methods of the container object class? For example: class Container(object): def __init__(self): self.actions = {} self.actions['foo'] = self.foo self.value = 3 def foo(self): print 'foo', self.value c = Container() c.actions['foo']() Otherwise I would go with Alan's suggestion of passing the parent to the action class constructor. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor