Best way to set/get an object property

castironpi castironpi at
Sun Aug 24 16:12:22 CEST 2008

On Aug 24, 5:07 am, Hussein B <hubaghd... at> 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.

The answer Hussein is you have both options in Python.  If neither one
is clearly better-suited to your new application, pick one and go.

More information about the Python-list mailing list