On Dec 12, 2007 12:53 PM, George Sakkis <[EMAIL PROTECTED]> wrote: > On Dec 12, 1:12 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > > > Kay Schluehr wrote: > > > class A(object): > > > foo = property: > > > def fget(self): > > > return self._foo > > > def fset(self, value): > > > self._foo = value > > > > > which was translated as follows: > > > > > class A(object): > > > def thunk(): > > > def fget(self): > > > return self._foo > > > def fset(self, value): > > > self._foo = value > > > return vars() > > > foo = propery(**thunk()) > > > del thunk > > > > Python 2.6 and 3.0 have a more Pythonic way for the problem: > > > > class A(object): > > @property > > def foo(self): > > return self._foo > > > > @foo.setter > > def foo(self, value) > > self._foo = value > > > > @foo.deletter > > def foo(self) > > del self._foo > > > > class B(A): > > # one can even overwrite the getter in a subclass > > @foo.getter > > def foo(self): > > return self._foo * 2 > > > > Christian > > This is by definition Pythonic since it was conceived by the BDFL.It > is also certainly an improvement over the current common practice of > polluting the class namespace with private getters and setters. Still > it's a kludge compared to languages with builtin support for > properties.
How exactly is this a kludge? This is almost identical syntax (but with less indentation) to a C# property declaration. The only thing that's simpler is auto-generation of trivial accessors via a decoration, but those are useless in Python so only the case of getters and setters that actually do something needs to be addressed. If the only thing that's not a "kludge" is direct syntax support for a feature, you've set a pretty high and uselessly arbitrary bar. -- http://mail.python.org/mailman/listinfo/python-list