bound|bound method/unbound method/function

class _C: def _m(self): passc = _C() c._m > _C._m _C.__dict__['_m'] ========================================== type(_C.__dict__['_m']) type(_C._m) type(c._m) ========================================== func func.im_func func.im_self is None True # 因为这是一个unbound method func.im_class

【bound|bound method/unbound method/function】实际上类的方法都会被转换为非数据型描述符
def demo_function(*args,**kwargs): print args,kwargsclass FooClass(object): def demo_method(self): passdemo_method2 = demo_functionfoo_instance = FooClass()print FooClass.__dict__['demo_method2']() #什么输出都没有 print FooClass.demo_method2() # 报错TypeError: unbound method demo_function() must be called with FooClass instance as first argument (got nothing instead)也就是说,python回去检查第一个参数是什么 print FooClass.demo_method2(foo_instance ) print foo_instance.demo_method2()

    推荐阅读