Attribute monitoring in a class

Simon Brunning simon at brunningonline.net
Wed Mar 14 06:45:05 EDT 2007


On 3/14/07, Joel Andres Granados <joel.granados at gmail.com> wrote:
> 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????

You want __setttr__(). See <http://docs.python.org/ref/attribute-access.html>.

-- 
Cheers,
Simon B
simon at brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning
MSN: small_values



More information about the Python-list mailing list