Wanting to fire an event when property content changes

Albert Hopkins marduk at letterboxes.org
Tue Mar 3 14:54:44 EST 2009


On Tue, 2009-03-03 at 13:41 -0600, nuwandame wrote:
> What I am wanting to do is execute code whenever a property of a class
> object has been changed.
> 
> i.e.
> 
> class test:
> 
>     testproperty = None
> 
> 
> bob = test()
> bob.testproperty = 'something'
> 
> So, when bob.testproperty is set to a new value I can run code that
> changes other dependent yet loosly tied properties in containing class
> objects.
> 
> I have looked at using metaclass for this but havn't found anything for
> property attributes, just methods...
> 
> Anyone have ideas how this can be done?

Use Python properties:

http://docs.python.org/library/functions.html#property





More information about the Python-list mailing list