Automatic Generation of Python Class Files
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Oct 22 16:23:11 EDT 2007
Steven Bethard a écrit :
(snip)
> In Python, you can use property() to make method calls look like
> attribute access. This could be necessary if you have an existing API
> that used public attributes, but changes to your code require those
> attributes to do additional calculations now.
>
> But if you're creating a class for the first time, it should *never* use
> property(). There's no need to retrofit anything.
May I kindly disagree here ?-)
Computed attributes are IMHO not only a life-saver when it comes to
refactoring. There are cases where you *really* have - by 'design' I'd
say - the semantic of a property, but know from the start you'll need
computation (for whatever reason). Then what would be the rationale for
using explicit getters/setters ?
More information about the Python-list
mailing list