1 class C: 2 def f(self): 3 print self 4 return self.value() 5 6 def value(self): 7 return 123 8 9 c = C() 10 11 class D: 12 f = c.f 13 14 d = D() 15 16 def fn(): 17 return 456 18 19 class E: 20 f = fn 21 g = C.f 22 23 e = E() 24 25 print c.f.__name__ # f 26 print c.f() # <__main__.C instance> 27 # 123 28 print d.f.__name__ # wrapper 29 print d.f() # <__main__.C instance> 30 # 123 31 32 print e.f.__name__ # fn 33 print e.f() # 456 34 print e.g.__name__ # f 35 36 try: 37 print e.g() 38 except TypeError: 39 print "e.g(): e is an incompatible instance for E.g which is C.f" 40 41 g = get_using(E.g, c) 42 print g.__name__ # f 43 print g() # <__main__.C instance> 44 # 123