Re: built-in 'property'

2004-12-30 Thread Steven Bethard
Sean Ross wrote: I'll note that it is possible to change the built-in property (in a backward compatible manner) to be used as a decorator for this idiom, to redefine parts of properties in sub-classes, and to provide default get/set/del methods. Is there a recipe or blog or something somewhere tha

Re: built-in 'property'

2004-12-30 Thread Sean Ross
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [snip] > For this reason, I usually suggest declaring properties like[1]: > > py> class E(object): > ... def x(): > ... def get(self): > ... return float(self._x) > ... def set(self, x): > .

Re: built-in 'property'

2004-12-29 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote: > For this reason, I usually suggest declaring properties like[1]: > > py> class E(object): > ... def x(): > ... def get(self): > ... return float(self._x) > ... def set(self, x): > ... self._x = x**2 > ...

RE: built-in 'property'

2004-12-28 Thread Bob . Cowdery
Title: RE: built-in 'property' Thanks to everyone that has helped on this. What I am trying to do is create a capability based api that I can build to order. This is as far as I get at the moment. Each of the first three classes represents some function I can do to a radio, ther

Re: built-in 'property'

2004-12-28 Thread Steven Bethard
Steven Bethard wrote: I seem to be missing some of the messages on this thread, but while we're talking about properties, it's probably instructive to remind people that the functions passed to the property function are not redefinable in subclasses: py> class D(C): ... def getx(self): ...

Re: built-in 'property'

2004-12-28 Thread Steven Bethard
Stian Søiland wrote: On 2004-12-28 12:05:20, [EMAIL PROTECTED] wrote: class NOTOK(object): def __init__(self): self.__x = 0 self.x = property(self.getx, self.setx, self.delx, "I'm the 'x' property.") def getx(self): return self.__x - 5 def setx(self, value): self

Re: built-in 'property'

2004-12-28 Thread Stian Søiland
On 2004-12-28 12:05:20, [EMAIL PROTECTED] wrote: > class NOTOK(object): > > def __init__(self): > self.__x = 0 > self.x = property(self.getx, self.setx, self.delx, "I'm the 'x' > property.") > > def getx(self): return self.__x - 5 > def setx(self, value):

RE: built-in 'property'

2004-12-28 Thread Bob . Cowdery
Title: RE: built-in 'property' What I want to achieve is a class whereby I can set the property access per instance so the user can test if a property is present using hasattr(klass,'prop') such that the instance has a given capability that can easily be tested by the user

Re: built-in 'property'

2004-12-27 Thread Shalabh Chaturvedi
[EMAIL PROTECTED] wrote: Hi Can any one explain how property works. It seems to be fine if executed on import i.e. if the property statement is at class scope. Properties are meant to be used at the class scope. A property is a kind of descriptor. See http://users.rcn.com/python/download/Descr