__parent__ - like attribute?

Dylan Reinhardt python at dylanreinhardt.com
Sat Jan 18 20:23:45 EST 2003


Seems like this should be easy, but I'm having a tough time figuring out 
how to change an attribute in a parent object *as a side effect* of a 
method called on a subobject.

An quick example:

-------------------------

class spam:
     __init__(self):
         self.stuff = eggs()
         self.changed = 0

class eggs:
     def do_stuff(self):
         # after we've done the main part of our work,
         # signal parent object that information has changed
         self.__some_namespace_voodoo__.changed = 1
         return something_unrelated

a = spam()
b = spam()
x = a.stuff.do_stuff()   #  <--- should set value of a.changed to 1
x = b.stuff.do_stuff()   #  <--- should set value of b.changed to 1

-------------------------

If this looks like manipulation of the _p_changed attribute in ZODB, it's 
not a coincidence... that's what I'm hoping to use this for.  I realize I 
could pull a reference to a from globals() assuming I know the parent class 
is called "a" or "b", but I'm hoping there's a way to go about this without 
storing the parent name in every sub-object.

Any pointers and/or nudges in the right direction will be greatly appreciated.

Thanks,

Dylan






More information about the Python-list mailing list