__parent__ - like attribute?

holger krekel pyth at devel.trillke.net
Sat Jan 18 22:20:31 EST 2003


Dylan Reinhardt wrote:
> 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.

I doubt that this is currently possible to do correctly.  It would
be a bit messy at least.  you can split your problem:

1. getting to the callers 'context' which is represented by a 
   Frame object.  This is easy and the inspect method offers
   a way to do this (inspect.getcurrentframe(1)).

2. find an instance (if any) on which you want to modify attributes.
   And here it gets very difficult.  How would you find it? 
   What if the actual instance just triggered a function 
   doing the actual call?  

Suppose we just want to get "the" instance from the last callers
execution context.  Even then it is kind of hard to get to
the instance.  Or to a bound instance function.  I don't think 
you can simply get to a non-instance function starting from a 
frame object. 

So the answer is: you can't do anything like this without 
defining exact semantics and then doing some "interesting" 
hacks to approximately get that. 

    holger





More information about the Python-list mailing list