property() usage - is this as good as it gets?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Aug 26 10:30:04 CEST 2008

David Moss a écrit :
> Hi,
> I want to manage and control access to several important attributes in
> a class and override the behaviour of some of them in various
> subclasses.
> Below is a stripped version of how I've implemented this in my current
> bit of work.
> It works well enough, but I can't help feeling there a cleaner more
> readable way of doing this (with less duplication, etc).
> Is this as good as it gets or can this be refined and improved
> especially if I was to add in a couple more attributes some fairly
> complex over-ride logic?

(snip code)

Remember that properties have nothing magical - they're just one 
possible (and very handy) way to use the descriptor protocol to 
implement computed attributes. If you have to resort to any non-obvious 
trick or just too much boilerplate code with properties, then it's 
probably time to implementent your own custom descriptor object.

More information about the Python-list mailing list