TypeError: unbound method func1() must be called with base1 instance as first argument (got nothing

参考:python核心编程-------调用绑定方法

参考:http://blog.csdn.net/qinglu000/article/details/50960966

----------------------------------------------------------------------------------------------------------------------

parent.py 

  1 class base1(object):
  2     def __init__(self):
  3         pass
  4 
  5     def func1(self):
  6         a="func1"
  7         return a    

child1.py

  1 from parent import base1                                                                                                        
  2 
  3 
  4 class child1(base1):
  5     def __init__(self):
  6         pass
  7         
  8     def func2(self):
  9         #a=self.func1()      #OK
 10         #Error,TypeError: unbound method func1() must be called with base1 instance as first argument (got nothing instead)
 11         #a=base1.func1()    
 12         #a=func1()           #Error,NameError: global name 'func1' is not defined
 13         b="child_func1"     
 14         return a,b 
 15         
 16 
 17 if __name__ == "__main__":
 18      inst1=child1()
 19      print inst1.func2()


你可能感兴趣的:(TypeError: unbound method func1() must be called with base1 instance as first argument (got nothing)