Confusion about decorators

Arnaud Delobelle arnodel at gmail.com
Mon Dec 12 09:01:31 EST 2011


On 12 December 2011 13:52, Henrik Faber <hfaber at invalid.net> wrote:
> On 12.12.2011 14:45, Arnaud Delobelle wrote:
>
>>> Can someone please enlighten me?
>>
>> You can (need to?) use the descriptor protocol to deal with methods.
>>
>> from functools import partial
> [...]
>>        def __get__(self, obj, objtype):
>>                return partial(self, obj)
>
> Whoa. This is absolutely fantastic, it now works as expected (I get a
> reference to "self").
>
> I am very amazed -- I've been programming Python for about 5 years now
> and have never even come close to something as a "descriptor protocol".
> Python never ceases to amaze me. Do you have any beginners guide how
> this works? The Pydoc ("Data Model") is comprehensive, but I really
> don't know where to start to look.

Well, I've been using Python for 10 years :)  The best reference I know is:

http://users.rcn.com/python/download/Descriptor.htm

-- 
Arnaud



More information about the Python-list mailing list