ionel's codelog

Functions are descriptors

Sun 26 October 2008

I didn't knew that till i've read Ian's post on decora-descriptors (I guess I can call them that). Actually it's explained in more details here.

On short, functions have the __get__ method that make them work as descriptors when they are in a class.

I can do this:

>>> class Bar:
...     pass
...
>>> bar = Bar()
>>>
>>> def foo():
...     pass
...
>>> foo

>>>
>>> foo.__get__(None, Bar)

>>>
>>> foo.__get__(bar, Bar)
>

Neat !

This entry was tagged as python

blog comments powered by Disqus