Python super (class, self). Method versus super (parent, self). Method

This question follows from the next question , say class Bextendsclass 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 the difference?
+4
source share
1 answer
super(B,self).do_work()

calls the function do_work, as shown in the parent class B, that is A.do_work.


super(A,self).do_work()

will call the function do_work, as shown by the parent class A, i.e. object.do_work(which probably does not exist, and probably can throw an exception).

+11
source

All Articles