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 6722501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:27:17+00:00 2026-05-26T09:27:17+00:00

When inheriting from two objects like these class Foo(object): def __init__(self,a): self.a=a class Bar(object):

  • 0

When inheriting from two objects like these

class Foo(object):
  def __init__(self,a):
    self.a=a

class Bar(object):
  def __init__(self,b):
    self.b=b

I would normally do something like this

class FooBar(Foo,Bar):
  def __init__(self,a,b):
    Foo.__init__(self,a)
    Bar.__init__(self,b)

How does super know if I want to call both? and if so how will it know which argument to pass where. Or is it simply not possible to user super here?

Even if Foo and Bar take the same arguments can super deal with this?

Or should I not be trying to do this kind of this in the first place?

  • 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-26T09:27:18+00:00Added an answer on May 26, 2026 at 9:27 am

    Using super(), __init__() and multiple inheritance is a bit tricky.

    In the normal flow of things, every method calls super(), with the classes that inherit only from object doing a little extra work to make sure that the method actually exists: it’ll look a bit like this:

    >>> class Foo(object):
    ...     def frob(self, arg):
    ...         print "Foo.frob"
    ...         if hasattr(super(Foo, self), 'frob'):
    ...             super(Foo, self).frob(arg)
    ... 
    >>> class Bar(object):
    ...     def frob(self, arg):
    ...         print "Bar.frob"
    ...         if hasattr(super(Bar, self), 'frob'):
    ...             super(Bar, self).frob(arg)
    ... 
    >>> class Baz(Foo, Bar):
    ...     def frob(self, arg):
    ...         print "Baz.frob"
    ...         super(Baz, self).frob(arg)
    ... 
    >>> b = Baz()
    >>> b.frob(1)
    Baz.frob
    Foo.frob
    Bar.frob
    >>> 
    

    But when you try to do something similar on a method that object actually has, things get a little dicey; object.__init__ doesn’t take arguments, so about the only safe way to use it is to call super().__init__() with no arguments, since that call might be handled by object.__init__. But then it might not be handled by object.__init__, and instead handled by a class elsewhere in the inheritance graph. Thus any class which defines __init__ in a multiple inheritance class heirarchy must be prepared to be called with no arguments.

    one way of dealing with this is to never use arguments in __init__(). Do minimal initialization, and rely on setting properties or using other means to configure the new object before use. That’s pretty unpleasant, though.

    Another way is to use only keyword arguments, something like def __init__(self, **keywords): and always remove the arguments that apply to the given constructor. This is a hope based strategy, you hope that all of the keywords get consumed before control reaches object.__init__.

    A third way is to define a superclass to all of the multiple-inheritable bases which itself defines __init__ in some useful way and does not call super().__init__ (object.__init__ is a no-op anyway). This means you can be sure that this method is always called last, and you can do whetever you like with your arguments.

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

Sidebar

Related Questions

Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return
Say we have a class inheriting from two base classes (multiple inheritance). Base class
I have a project that has mainly two objects, both inheriting from a base.
I have two objects, and one inherites from the other. the parent object sends
Say I am inheriting from a class with several overloaded constructors. By any chance
I'd like to find all the types inheriting from a base/interface. Anyone have a
I've noticed that when you create a web service object (inheriting from SoapHttpClientProtocol) and
I wish to declare a new dojo class inheriting from an existing dojo class,
I have two classes (let's call them A and B ), both inheriting from
Summary Let's say I have two C# 4.0 classes, one inheriting from the other:

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.