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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:38:49+00:00 2026-06-04T14:38:49+00:00

Why don’t I ever see the following in Python code? class A: def __init__(self,

  • 0

Why don’t I ever see the following in Python code?

class A:
    def __init__(self, ...):
        # something important

class B(A):
    __init__ = A.__init__

It seems to work on my box with Python 2.5, 2.6, 2.7, and PyPy 1.8.

I see the following a lot, instead:

class B(A):
    def __init__(self, *args, **kwargs):
        A.__init__(self, *args, **kwargs)

or something using super.

I like my first example better (explicit is better than implicit!) but I’m worried that it’s not kosher for some reason. Is there something wrong or bad with it?

EDIT: Yep, I meant A.__init__, not self.__init__

  • 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-06-04T14:38:51+00:00Added an answer on June 4, 2026 at 2:38 pm

    Sure, it’ll work (assuming you get it right, which it is not in your example), but there’s no reason to do it. If you want B to call A‘s __init__(), just don’t define __init__() on B and that’ll happen automatically. That’s the whole point of inheritance, after all.

    The only reason you’d ever want to write an __init__() for B is if you wanted to do something when initializing a B instance in addition to what is done to initialize an A instance. In that case you’d write additional code besides just calling A.__init__(), so a simple assignment wouldn’t suit there, either.

    I suppose you could use this if you wanted to protect B‘s __init__() from being changed by a monkey-patch to A. But that seems like rather an edge case. Worse, it’s unexpected behavior and a blatant denial of Python’s dynamic nature.

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

Sidebar

Related Questions

Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
don't know better title for this, but here's my code. I have class user
Don't be scared of the extensive code. The problem is general. I just provided
Don't ask me why but I need to do the following: string ClassName =
I don't know if this is a well known 'thing' or something new in
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't be frightened, its a very basic code. Just wanted to check with you
Don't they both have to convert to machine code at some point to execute
Don't know a whole lot about streams. Why does the first version work using
Don't ask me how but I managed to get accidentally the following remote branches

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.