class method object def __init__ self self def __get__ self obj _t fro

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
>>> class method(object):
... def __init__(self, f):
... self.f = f
... def __get__(self, obj, _t):
... from functools import partial
... return partial(self.f, obj)
...
>>> class A(object):
... c = 10
... a = method(lambda self, i: self.c + i)
...
>>> A()
<__main__.A object at 0x106d4b890>
>>> A().a
<functools.partial object at 0x106d3adb8>
>>> A().a(10)
20
>>>