a Python person's experience with Ruby

Virgil Dupras hardcoded.software at gmail.com
Mon Dec 10 03:36:59 EST 2007


On Dec 9, 1:15 am, Bruno Desthuilliers
<bdesth.quelquech... at free.quelquepart.fr> wrote:
> 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.

I like Guido's proposal for read/write properties.
http://mail.python.org/pipermail/python-dev/2007-November/075182.html

It works pretty well and is readable.



More information about the Python-list mailing list