a Python person's experience with Ruby

Richard Jones richardjones at optushome.com.au
Sat Dec 8 18:35:02 EST 2007


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, yet is more complicated
and obfuscated to boot ;)

class A(object):
    def set_a(self, value):
        self._a = value
    a = property(lambda self: self._a, set_a)

Note that this differs from a regular attribute because "a" is not deletable
from instances (the property defines no deleter).


     Richard




More information about the Python-list mailing list