Attribute monitoring in a class

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Mar 14 19:26:14 EDT 2007


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. See
<http://dirtsimple.org/2004/12/python-is-not-java.html>

-- 
Gabriel Genellina




More information about the Python-list mailing list