static, class and instance methods (Reposting On Python-List Prohibited)

ast nomail at com.invalid
Thu Oct 6 11:13:11 EDT 2016


"Steve D'Aprano" <steve+python at pearwood.info> a écrit dans le message de 
news:57f6673a$0$1598$c3e8da3$5496439d at news.astraweb.com...
> On Thu, 6 Oct 2016 08:03 pm, ast wrote:
>
>> Consider this function:
>>
>> def add(a, b):
>>     return a+b
>>
>> You say that a function is always stored as
>> a descriptor object, so when I execute
>>
>> sum = f(4, 6)
>>
>> from which class it is supposed to come from ?
>
>
> It doesn't. The descriptor protocol only gets called by classes, so when you
> call a function directly, the special __get__ method isn't used.
>
>

yes, it is clear, thanks to all
(I didn't know that functions were descriptors with a __get__ method) 




More information about the Python-list mailing list