[Python-Dev] Re: Extended Function syntax (original) (raw)
Gerald S. Williams gsw@agere.com
Tue, 28 Jan 2003 13:01:22 -0500
- Previous message: [Python-Dev] Re: [Python-checkins] python/dist/src/Lib/bsddb dbshelve.py,1.4,1.4.4.1
- Next message: [Python-Dev] RE: Extended Function syntax
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Just van Rossum wrote:
With MWH's patch, this could be:
class Foo(object): class myprop [property]: """A computed property on Foo objects.""" def get(self): return ... def set(self): ... def delete(self): ...
That doesn't feel right to me. You generally want self to refer to the Foo object, don't you? With the class notation, I'd expect self to refer to Foo.myprop objects. I know they're properties of the Foo object, but somehow it still seems like a stretch.
Manual Garcia's recommendation seems cleaner:
j = block: def getj(self): return self.j def setj(self, j): self.j = j return property(getj, setj, None, 'dynamite!')
Although the following idiom works fine for me:
class Parrot(object): def count(): "Treat mostly-parrots as full parrots." def Get(self): return self._count def Set(self,count): self._count = int(round(count)) def Del(self): self._count = 0 return property(Get,Set,Del,"Current parrot count") count = count()
-Jerry
- Previous message: [Python-Dev] Re: [Python-checkins] python/dist/src/Lib/bsddb dbshelve.py,1.4,1.4.4.1
- Next message: [Python-Dev] RE: Extended Function syntax
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]