Best way to set/get an object property

Ken Seehart ken at seehart.com
Mon Aug 25 06:15:01 EDT 2008


This is probably what you want:

http://www.python.org/download/releases/2.2/descrintro/#property

Available in Python 2.2 or later.

Enjoy,
Ken Seehart

Hussein B wrote:
> Hey,
> I noted that Python encourage the usage of:
> --
> obj.prop = data
> x = obj.prop
> --
> to set/get an object's property value.
> What if I want to run some logic upon setting/getting a property?
> What is Python preferred method to do so (using the new feature
> 'property')?
> I don't think __getattr__ and __setattr__ are practical (I have to
> code the property name into them).
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   




More information about the Python-list mailing list