Python super(Class, self).method vs super(Parent, self).method

后端 未结 1 1696
难免孤独
难免孤独 2020-12-31 17:36

This question is derive from the following question, let\'s say class B extends class A

class A(object):
  def do_work(self):
    p         


        
相关标签:
1条回答
  • 2020-12-31 18:35
    super(B,self).do_work()
    

    will call the do_work function as seen by the parent class of B - that is, A.do_work.


    super(A,self).do_work()
    

    will call the do_work function as seen by the parent class of A - that is, object.do_work (which probably doesn't exist, and thus would likely raise an exception).

    0 讨论(0)
提交回复
热议问题