detecting property modification
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Fri Dec 21 16:46:33 EST 2007
Mangabasi a écrit :
(snip)
>
> When you say "The Body gets asked for the value of the attribute" that
> means that Body's __dict__ is being asked to provide a value
> corresponding to its 'pos' key, right?
Wrong. That means that attribute lookup rules are invoked, which may *or
not* end up calling the Body *intance*'s __dict__ __setitem__ method to
be called. Anyway:
> Now I may want to ask a more
> specific question here. How do I modify Body's __dict__ so that I can
> perform a task when __getitem__ method of the __dict__ is called?
This still won't solve your problem. What you want to trace are method
calls on the objects returned by attribute lookup on instances of Body -
not calls to instances __dict__ methods. In your example, what you want
to trace are calls to pos.__getitem__, not calls to b.__dict__.__getitem__.
And if you what you really want is to trace any mutator call to any
arbitrary object that may become an attribute of b, then I'm afraid
you're in for a hard time...
More information about the Python-list
mailing list