[Python-au] New Python Class Features
Fri, 17 Jan 2003 15:04:59 +1100
On Fri, Jan 17, 2003 at 02:39:16PM +1100, Graeme Matthew wrote:
> Hi all
> When designing Classes does one have to set getters and setters
Generally you don't bother.
self.order = None
o = Order()
o.order = 'foo'
> class Order(object):
> def __init__ (self):
> self.__order = None
> def get_order(self):
> return self.__order
> def set_order(self, val):
> self.__order = val
> order = property(get_order, set_order)
I'd recommend only using property for computed attributes (i.e. ones that
need a function call to calculate their value). Most of the time you don't
> What I am trying to determine if their is a short way as this is going to
> take ages when writing an object that has 20 properties
Just use the simplest thing that works -- accessing the attributes directly.
Is there any particular reason why you wanted to use properties?