[Python-Dev] Definining properties - a use case for class decorators?
Michele Simionato
michele.simionato at gmail.com
Tue Oct 18 17:38:40 CEST 2005
On 10/18/05, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Le mardi 18 octobre 2005 à 10:57 -0400, Barry Warsaw a écrit :
> Currently I never use properties, because it makes classes much less
> readable for the same kind of reasons as what Jim wrote.
Me too, I never use properties directly. However I have experimented
with using helper functions to generate the properties:
_dic = {}
def makeproperty(x):
def getx(self):
return _dic[self, x]
def setx(self, value):
_dic[self, x] = value
return property(getx, setx)
class C(object):
x = makeproperty('x')
c = C()
c.x = 1
print c.x
But in general I prefer to write a custom descriptor class, since it
gives me much more control.
Michele Simionato
More information about the Python-Dev
mailing list