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

  • SEARCH
  • Home
  • 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 1077905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:38:44+00:00 2026-05-16T21:38:44+00:00

firstly, let me quote a bit an essay from Expert Python Programming book: In

  • 0

firstly, let me quote a bit an essay from “Expert Python Programming” book:

In the following example, a C class that calls its base classes using the __init__ method will
make B class be called twice!

class A(object):
    def __init__(self):
        print "A"
        super(A, self).__init__()

class B(object):
    def __init__(self):
        print "B"
        super(B, self).__init__()

class C(A,B):
    def __init__(self):
        print "C"
        A.__init__(self)
        B.__init__(self)

print "MRO:", [x.__name__ for x in C.__mro__]  #prints MRO: ['C', 'A', 'B', 'object']
C()  #prints C A B B

and finally, here is an explanation of what’s going on here:

This happens due to the A.__init__(self) call, which is made with the C instance,
thus making super(A, self).__init__() call B’s constructor.
In other words,
super should be used into the whole class hierarchy. The problem is that sometimes
a part of this hierarchy is located in third-party code.

i have no idea why “super(A, self).__init__() calls B’s constructor”. Please explain this moment. Thanks a lot.

  • 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. Editorial Team
    Editorial Team
    2026-05-16T21:38:44+00:00Added an answer on May 16, 2026 at 9:38 pm

    The documentation for super says that:

    Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.

    When you execute A.__init__(self) from within C the super(A, self) will return <super: <class 'A'>, <C object>>. As the instance is C (<C object>) all the classes in C’s inheritance hierarchy are picked up. And the __init__ call is issued on all of them. Consequently you see ‘B’ getting called twice.

    To verify this add another class ‘Z’ and let ‘C’ inherit from ‘Z’ as well. See what happens.

    class Z(object):
        def __init__(self):
            print "Z"
            super(Z, self).__init__()
    
    class C(A, B, Z):    
        def __init__(self):
            print "C"
            A.__init__(self)
            B.__init__(self)
            Z.__init__(self)
    

    In this case, A will call B and Z. B will call Z as well.

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

Sidebar

Related Questions

Firstly, let me start by saying that I haven't ever directly used SQL views.
Firstly, let me say that I've been searching the Internet, rewriting scripts and I
Firstly, let me say that I've been on this issue for pretty much 2
Firstly, let me say that I know that http://sphinxsearch.com/docs/current.html#conf-sql-attr-string says strings can only be
Firstly, let me just say that I'm very new to JSR-170 and Jackrabbit/Lucene in
Let's consider I want to create the following hierarchy: Animal -> Class (mammal, amphibian,
Possible Duplicate: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive Firstly, let me
How could I send an e-mail from my Python script that is being run
Firstly let me clarify (if the title wasn't clear enough): I'm discussing System.Windows.Controls.DataGrid from
Firstly let me clarify (if the title wasn't clear enough): I'm discussing System.Windows.Controls.DataGrid from

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.