Properties/Decorators [WAS: Can I reference 1 instance of an object by more names ? rephrase]

Wildemar Wildenburger wildemar at freakmail.de
Wed May 23 08:43:12 EDT 2007


Bruno Desthuilliers wrote:
> here's an example using a property:
>
> class cpu_ports(object):
>     def __init__(self, value=0):
>         self._d = value
>     @apply
>     def value():
>         def fset(self, value):
>             print 'vv'
>             self._d = value
>         def fget(self):
>             return self._d
>         return property(**locals())
>   
Wow! I've never seen properties written that way. Kind of takes all the 
mess out of what it usually is. Nice. BUT! I don't quite get the 
@apply-decorator here. The rest I get and so I gather what it is sort of 
kind of supposed to do. I have only found the depricated apply() 
function in the docs (which I also don't quite get just by scanning it). 
Is it that? If yes: How does it work? If not: What's going on there?

humbly ;)
W



More information about the Python-list mailing list