Attribute monitoring in a class

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Mar 15 04:36:32 EDT 2007


Gabriel Genellina a écrit :
> En Wed, 14 Mar 2007 10:01:54 -0300, Joel Andres Granados 
> <joel.granados at gmail.com> escribió:
> 
>> Bruno Desthuilliers wrote:
>>> Joel Andres Granados a écrit :
> 
>>>> 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) )
> 
>>> yes : object.__setattr__(self, name, value)
>> I used this ^^^^^^^^^^^^^^^ one.  Thank for the help.
> 
> The problem with __setattr__ is that it slows down significantly *all* 
> attributes.
> Yours is the typical case when it's good to switch from using simple 
> attributes to using properties. 

If this has to become a feature of the class, yes, indeed. If it's just 
a temporary hack for debugging, the using the __getattr__ hook is 
quicker and less intrusive.




More information about the Python-list mailing list