method to create class property
Diez B. Roggisch
deets at nospam.web.de
Tue Mar 18 18:09:57 EDT 2008
Joe P. Cool schrieb:
> On 18 Mrz., 21:59, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>> Joe P. Cool schrieb:
>>> def _property_y(self):
>>> def _get(self):
>>> [...]
>> There are a few recipies, like this:
>>
>> class Foo(object):
>>
>> @apply
>> def foo():
>> def fget(self):
>> return self._foo
>> def fset(self, value):
>> self._foo = value
>> return property(**locals())
>
> This is really cool! Thanks, Diez! I should definitely
> learn to handle decorators :) But isnt't apply bound to
> be dropped in Python 3.0?
In python 3.0, there will be an even nicer way - propset:
@property
def foo(self):
return self._foo
@propset
def foo(self, value):
self._value = value
Diez
More information about the Python-list
mailing list