简体   繁体   中英

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

This question is derive from the following question , let's say class B extends 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?
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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM