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()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章