1 class C: 2 def __init__(self): 3 self.x = 123 4 5 def f(self): 6 return self.x 7 8 class D: 9 pass 10 11 c = C() 12 f = C.f 13 fn = get_using(C.f, c) 14 print fn # __main__.C.f 15 print fn() # 123 16 17 fn = get_using(C.f, C) 18 print fn # __main__.C.f 19 try: 20 print fn() # fails 21 except UnboundMethodInvocation: 22 print "fn(): method is unbound" 23 24 d = D() 25 try: 26 fn = get_using(C.f, d) 27 except TypeError: 28 print "get_using(C.f, d): d is not compatible with C" 29 30 fn = get_using(c, C.f) 31 print fn # <__main__.C instance> 32 try: 33 print fn() # fails 34 except TypeError: 35 print "fn(): object is not callable"