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

ast nomail at com.invalid
Fri Oct 7 01:01:04 EDT 2016


"Gregory Ewing" <greg.ewing at canterbury.ac.nz> a écrit dans le message de 
news:e5mgi9Fp1bsU1 at mid.individual.net...
> Lawrence D’Oliveiro wrote:
>>
>> Every function is already a descriptor.
>
> Which you can see with a simple experiment:
>
> >>> def f(self):
> ...  print("self =", self)
> ...

I thought yesterday that every thing was clear. But I have
a doubt now with the following line:

> >>> g = f.__get__(17, None)

The signature of  __get__ method is  __get__ (self, inst, owner)  so
once again the first parameter is filled automatically.
Is method __get__ itself a descriptor with an attribute __get__ to perform
the operation ? Hum, it would be endless ...

vars(f.__get__)
TypeError: vars() argument must have __dict__ attribute

no, so how does it work here ?






> >>> g
> <bound method f of 17>
> >>> g()
> self = 17
>
> -- 
> Greg 




More information about the Python-list mailing list