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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:47:49+00:00 2026-05-13T15:47:49+00:00

I have a class: class A(object): def __init__(self,a,b,c,d,e,f,g,………..,x,y,z) #do some init stuff And I

  • 0

I have a class:

class A(object):
    def __init__(self,a,b,c,d,e,f,g,...........,x,y,z)
        #do some init stuff

And I have a subclass which needs one extra arg (the last W)

class B(A):
    def __init__(self.a,b,c,d,e,f,g,...........,x,y,z,W)
        A.__init__(self,a,b,c,d,e,f,g,...........,x,y,z)
        self.__W=W

It seems dumb to write all this boiler-plate code, e.g passing all the args from B‘s Ctor to the inside call to A‘s ctor, since then every change to A‘s ctor must be applied to two other places in B‘s code.

I am guessing python has some idiom to handle such cases which I am unaware of. Can you point me in the right direction?

My best hunch, is to have a sort of Copy-Ctor for A and then change B’s code into

class B(A):
     def __init__(self,instanceOfA,W):
         A.__copy_ctor__(self,instanceOfA)
         self.__W=W

This would suit my needs since I always create the subclass when given an instance of the father class, Though I am not sure whether it’s possible…

  • 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-13T15:47:49+00:00Added an answer on May 13, 2026 at 3:47 pm

    Considering that arguments could be passed either by name or by position, I’d code:

    class B(A):
        def __init__(self, *a, **k):
          if 'W' in k:
            w = k.pop('W')
          else:
            w = a.pop()
          A.__init__(self, *a, **k)
          self._W = w
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like the following: class Positive(object): def __init__(self, item): self._validate_item(item) self.item
Let's say I have this : class whatever(object): def __init__(self): pass and this function:
I have the following problem: I have the class: class Word(object): def __init__(self): self.id
I have class SomeClass with properties. For example id and name : class SomeClass(object):
I'd like to be able to have the operator of my class interact with
I recently discovered Python's property built-in , which disguises class method getters and setters
Is there a way in python to increment int object in place, int doesn't
Trying to change the __unicode__ method on an instance after it's created produces different
I'm new to the ideas of decorators (and still trying to wrap my head

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.