10

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?
Community
  • 1
  • 1
James Lin
  • 25,028
  • 36
  • 133
  • 233

1 Answers1

19
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).

Amber
  • 507,862
  • 82
  • 626
  • 550
  • if doing super(A, self).do_work is not the way to go, then how do I go about solving this problem? http://stackoverflow.com/questions/14739809/django-overwriting-modelform-save-causes-recursion Thanks! – James Lin Feb 07 '13 at 05:03
  • @JamesLin Added an answer on that question. – Amber Feb 07 '13 at 05:22