a Python person's experience with Ruby

Chris Mellon arkanes at gmail.com
Mon Dec 10 11:14:41 EST 2007


On Dec 9, 2007 5:11 AM, Arnaud Delobelle <arnodel at googlemail.com> wrote:
> On Dec 9, 12: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 !-)
>
> Perhaps 'return property(fget, fset)' would be easier to make sense of
> than **locals()
>
> > 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.
>
> At first sight, I like the look of this. Obviously I can't provide a
> builtin implementation, but there's an easy way to achieve this.  It
> uses sys._getframe but there is no need to fiddle with metaclasses:
>


Something very like this will be in 3k, and I believe is also being
backported to 2.6. See python-dev archives for more.



More information about the Python-list mailing list