[Python-Dev] RFC: readproperty (original) (raw)

Phillip J. Eby pje at telecommunity.com
Thu Sep 29 01:14:46 CEST 2005


At 06:23 PM 9/28/2005 -0400, Barry Warsaw wrote:

I /must/ be missing something. Why not just use property as a decorator?

class C: @property def eggs(self): print 'in eggs' self.eggs = 7 return self.eggs >>> c = C() >>> c.eggs in eggs 7 >>> c.eggs 7

Because it only works in classic classes due to a bug in descriptor handling:

class C(object): @property def eggs(self): print 'in eggs' self.eggs = 7 return self.eggs

c=C() c.eggs in eggs

Traceback (most recent call last): File "<pyshell#12>", line 1, in -toplevel- c.eggs File "<pyshell#10>", line 4, in eggs self.eggs = 7 AttributeError: can't set attribute



More information about the Python-Dev mailing list