This is a way to access functions when they are class attributes.
A function added as an attribute of a class is accessed as a descriptor . You see, if you do
class A(object): pass def f(*a): pass Af = f print f print Af print A().f
Here you get the conclusion
<function f at 0x00F03D70> <unbound method Af> <bound method Af of <__main__.A object at 0x00F089D0>>
You get the same thing with
print f print f.__get__(None, A) print f.__get__(A(), A)
because this is the way descriptors work.
All this β the conversion from function to method through the handle protocol β does not occur in instance attributes.
If you do
a = A() af = f
then af also read as a function, not as a method. Therefore, you should take this into account during the course of the assignment and, rather, do
af = lambda: f(a)
to pass a function.
source share