[Python-au] New Python Class Features

Andrew Bennetts andrew-pythonau@puzzling.org
Fri, 17 Jan 2003 15:32:27 +1100

On Fri, Jan 17, 2003 at 03:07:09PM +1100, Brian White wrote:
> At 15:04 17/01/2003, Andrew Bennetts wrote:
> >
> >Just use the simplest thing that works -- accessing the attributes
> >directly.  Is there any particular reason why you wanted to use
> >properties?
> In one sense it depends on how much of a purist you are!
> Using Get/Set methods means that at any time you can
> change the underlying storage or trigger events off the
> Get and Set

There are other ways to do this that don't require property :)

__{get,set}attr__ and __{get,set}attribute__ could also do this -- but
regardless of how the class is implemented, the user of the class is still

    o.foo = 1  # setting an attribute
    x = o.foo  # getting an attribute

What's happening behind the scenes is quite flexible, and can be changed
independently of how the class is used.  Thus I'd recommend using ordinary
attributes until you have some reason not to, because it all looks the same