Attribute monitoring in a class

Joel Andres Granados joel.granados at gmail.com
Wed Mar 14 06:33:03 EDT 2007


Hi list:

I have googled quite a bit on this matter and I can't seem to find what 
I need (I think Im just looking where I'm not suppose to :).  I'm 
working with code that is not of my authorship and there is a class 
attribute that is changes by directly referencing it (object.attr = 
value) instead of using a getter/setter (object.setAttr(Value) ) 
function.  The thing is that I have no idea when the change occurs and I 
would REALLY like to find out.
So here comes my question .....
Is there a function construct inside a python class that is 
automatically called when an attr is changed????
Like for example

/class Class:
    def __init__();
       self.attr = "whatever"

    def __attrChangeFunction__():
       print "It has changed"

obj = Class()
obj.attr = "other whatever"

*Output:*
It has changed

/
Thanks for the help.
Regards/
/



More information about the Python-list mailing list