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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:04:09+00:00 2026-05-28T19:04:09+00:00

So I was following Python’s Super Considered Harmful , and went to test out

  • 0

So I was following Python’s Super Considered Harmful, and went to test out his examples.

However, Example 1-3, which is supposed to show the correct way of calling super when handling __init__ methods that expect different arguments, flat-out doesn’t work.

This is what I get:

~ $ python example1-3.py 
MRO: ['E', 'C', 'A', 'D', 'B', 'object']
E arg= 10
C arg= 10
A
D arg= 10
B
Traceback (most recent call last):
  File "Download/example1-3.py", line 27, in <module>
    E(arg=10)
  File "Download/example1-3.py", line 24, in __init__
    super(E, self).__init__(arg, *args, **kwargs)
  File "Download/example1-3.py", line 14, in __init__
    super(C, self).__init__(arg, *args, **kwargs)
  File "Download/example1-3.py", line 4, in __init__
    super(A, self).__init__(*args, **kwargs)
  File "Download/example1-3.py", line 19, in __init__
    super(D, self).__init__(arg, *args, **kwargs)
  File "Download/example1-3.py", line 9, in __init__
    super(B, self).__init__(*args, **kwargs)
TypeError: object.__init__() takes no parameters

It seems that object itself violates one of the best practices mentioned in the document, which is that methods which use super must accept *args and **kwargs.

Now, obviously Mr. Knight expected his examples to work, so is this something that was changed in recent versions of Python? I checked 2.6 and 2.7, and it fails on both.

So what is the correct way to deal with this problem?

  • 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-28T19:04:10+00:00Added an answer on May 28, 2026 at 7:04 pm

    Sometimes two classes may have some parameter names in common. In that case, you can’t pop the key-value pairs off of **kwargs or remove them from *args. Instead, you can define a Base class which unlike object, absorbs/ignores arguments:

    class Base(object):
        def __init__(self, *args, **kwargs): pass
    
    class A(Base):
        def __init__(self, *args, **kwargs):
            print "A"
            super(A, self).__init__(*args, **kwargs)
    
    class B(Base):
        def __init__(self, *args, **kwargs):
            print "B"
            super(B, self).__init__(*args, **kwargs)
    
    class C(A):
        def __init__(self, arg, *args, **kwargs):
            print "C","arg=",arg
            super(C, self).__init__(arg, *args, **kwargs)
    
    class D(B):
        def __init__(self, arg, *args, **kwargs):
            print "D", "arg=",arg
            super(D, self).__init__(arg, *args, **kwargs)
    
    class E(C,D):
        def __init__(self, arg, *args, **kwargs):
            print "E", "arg=",arg
            super(E, self).__init__(arg, *args, **kwargs)
    
    print "MRO:", [x.__name__ for x in E.__mro__]
    E(10)
    

    yields

    MRO: ['E', 'C', 'A', 'D', 'B', 'Base', 'object']
    E arg= 10
    C arg= 10
    A
    D arg= 10
    B
    

    Note that for this to work, Base must be the penultimate class in the MRO.

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

Sidebar

Related Questions

Observe the following Python script, Script.py: import subprocess src_directory = 'Z:\z_7z\Some_Directory' zip_file_name = 'Test.7z'
I have the following python script which takes some inputs and puts them in
am reading out of a database with the following python script: cur.execute(SELECT * FROM
I have the following python code which in my opinion behaves strangely: Imported module:
I have the following Python code which I am using to plot a filled
If I have the following Python class: class Test(object): funcs = { me :
I have the following python code which pushes data to db: cursor.execute(INSERT INTO +
The following python code works but the maintainability is quite poor. However I'm failing
I have the following Python code which takes data from cassandra database. What i
I tried running the following python code in Eclipse on Windows but it is

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.