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


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to