a Python person's experience with Ruby

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Dec 8 19:15:39 EST 2007


Richard Jones a écrit :
> Bruno Desthuilliers wrote:
> 
>>class A(object):
>>   @apply
>>   def a():
>>     def fget(self):
>>       return self._a
>>     def fset(self, val):
>>       self._a = val
>>     return property(**locals())
>>   def __init__(self):
>>     self.a = "foo"
> 
> 
> That property setup seems overly complicated. As far as I can see, it only
> avoids defining the setter in the class namespace,

Yes. That's mosly the point.

> yet is more complicated
> and obfuscated to boot ;)

Well, that's your POV, so what can I say ? It's indeed a bit hackish, 
and requires a couple minutes of attention the first time you see it. 
And you just have to learn it once !-)

Now I'd certainly prefer something like:

class A(object):
    @propget
    def a(self):
      return self._a
    @propset
    def a(self, val):
      self._a = val

But until there's something similar *builtin*, I'll stick to the @apply 
trick.



More information about the Python-list mailing list