Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 156109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:16:26+00:00 2026-05-11T10:16:26+00:00

I’m running Python 2.5, so this question may not apply to Python 3. When

  • 0

I’m running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the derived-most class, then its parent classes as listed from left to right, then the grandparent. I’m familiar with Python’s MRO; that’s not my question. I’m curious how the object returned from super actually manages to communicate to calls of super in the parent classes the correct order. Consider this example code:

#!/usr/bin/python  class A(object):     def __init__(self): print 'A init'  class B(A):     def __init__(self):         print 'B init'         super(B, self).__init__()  class C(A):     def __init__(self):         print 'C init'         super(C, self).__init__()  class D(B, C):     def __init__(self):         print 'D init'         super(D, self).__init__()  x = D() 

The code does the intuitive thing, it prints:

D init B init C init A init 

However, if you comment out the call to super in B’s init function, neither A nor C’s init function is called. This means B’s call to super is somehow aware of C’s existence in the overall class hierarchy. I know that super returns a proxy object with an overloaded get operator, but how does the object returned by super in D’s init definition communicate the existence of C to the object returned by super in B’s init definition? Is the information that subsequent calls of super use stored on the object itself? If so, why isn’t super instead self.super?

Edit: Jekke quite rightly pointed out that it’s not self.super because super is an attribute of the class, not an instance of the class. Conceptually this makes sense, but in practice super isn’t an attribute of the class either! You can test this in the interpreter by making two classes A and B, where B inherits from A, and calling dir(B). It has no super or __super__ attributes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:16:27+00:00Added an answer on May 11, 2026 at 10:16 am

    I have provided a bunch of links below, that answer your question in more detail and more precisely than I can ever hope to. I will however give an answer to your question in my own words as well, to save you some time. I’ll put it in points –

    1. super is a builtin function, not an attribute.
    2. Every type (class) in Python has an __mro__ attribute, that stores the method resolution order of that particular instance.
    3. Each call to super is of the form super(type[, object-or-type]). Let us assume that the second attribute is an object for the moment.
    4. At the starting point of super calls, the object is of the type of the Derived class (say DC).
    5. super looks for methods that match (in your case __init__) in the classes in the MRO, after the class specified as the first argument (in this case classes after DC).
    6. When the matching method is found (say in class BC1), it is called.
      (This method should use super, so I am assuming it does – See Python’s super is nifty but can’t be used – link below) That method then causes a search in the object’s class’ MRO for the next method, to the right of BC1.
    7. Rinse wash repeat till all methods are found and called.

    Explanation for your example

     MRO: D,B,C,A,object   
    1. super(D, self).__init__() is called. isinstance(self, D) => True
    2. Search for next method in the MRO in classes to the right of D.

      B.__init__ found and called


    1. B.__init__ calls super(B, self).__init__().

      isinstance(self, B) => False
      isinstance(self, D) => True

    2. Thus, the MRO is the same, but the search continues to the right of B i.e. C,A,object are searched one by one. The next __init__ found is called.

    3. And so on and so forth.

    An explanation of super
    http://www.python.org/download/releases/2.2.3/descrintro/#cooperation
    Things to watch for when using super
    http://fuhm.net/super-harmful/
    Pythons MRO Algorithm:
    http://www.python.org/download/releases/2.3/mro/
    super’s docs:
    http://docs.python.org/library/functions.html
    The bottom of this page has a nice section on super:
    http://docstore.mik.ua/orelly/other/python/0596001886_pythonian-chp-5-sect-2.html

    I hope this helps clear it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The two general techniques: a) Set your Build Products directory… May 11, 2026 at 7:51 pm
  • Editorial Team
    Editorial Team added an answer Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition… May 11, 2026 at 7:51 pm
  • Editorial Team
    Editorial Team added an answer I would "swap" parts of the array out to disk.… May 11, 2026 at 7:51 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.