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

Jam*_*Lin 6 python inheritance parent super

这个问题来自以下问题,我们说class B延伸class A

class A(object):
  def do_work(self):
    print 123

class B(A):
  def do_work(self):
    super(B,self).do_work() # versus the next statement
    super(A,self).do_work() # what's the difference?
Run Code Online (Sandbox Code Playgroud)

Amb*_*ber 11

super(B,self).do_work()
Run Code Online (Sandbox Code Playgroud)

会调用do_work父类看到的函数B- 也就是说A.do_work.


super(A,self).do_work()
Run Code Online (Sandbox Code Playgroud)

将调用do_work父类看到的函数A- 即object.do_work(可能不存在,因此可能引发异常).