[Python-ideas] Callable properties
Michael Foord
fuzzyman at voidspace.org.uk
Mon Jun 7 15:40:36 CEST 2010
On 7 June 2010 12:34, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>
> [snip...]
> I think you misunderstood, he was suggesting making the property descriptor
> instances callable.
>
> Not a bad idea, but as a change to a builtin it would be covered by the
> language moratorium. Easy to do in a subclass of property though.
>
> At the moment you do the following, which is a bit ugly:
>
> >>> class Foo(object):
> ... @property
> ... def foo(self):
> ... return 'foo'
> ...
> >>> f = Foo()
> >>> Foo.foo.__get__(f)
> 'foo'
>
> The reason for wanting to do this are the same reasons as you would call an
> unbound method.
>
>
Or this which is still slightly ugly but at least gets rid of the magic
method call:
>>> class Foo(object):
... @property
... def foo(self):
... return 'foo'
...
>>> f = Foo()
>>> Foo.foo.fget(f)
'foo'
Michael
> Michael
>
>
>>
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas
>>
>
>
>
> --
> http://www.voidspace.org.uk
>
>
>
--
http://www.voidspace.org.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100607/5b9d816f/attachment.html>
More information about the Python-ideas
mailing list