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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:55+00:00 2026-05-26T20:11:55+00:00

class baseClass(): def __init__(self,mark,name): self.mark = mark self.name = name class derivedClass(baseClass): b1 =

  • 0
class baseClass():
  def __init__(self,mark,name):
    self.mark = mark
    self.name = name

class derivedClass(baseClass):

b1 = derivedClass(name='Jibin')
print b1.name

This was my code initially & it worked fine.

(Note: I don’t have access to baseClass)

But later I had to pass a additional attribute rank to derivedClass.So I edited the code like this.

class baseClass():
  def __init__(self,mark,name):
    self.mark = mark
    self.name = name

class derivedClass(baseClass):
  def __init__(self,rank):
    self.rank = rank 

b1 = derivedClass(name='Jibin')
print b1.name

This caused an error __init__() got an unexpected keyword argument 'name'

This was expected as the __init__ of derivedClass do not have a argument name.

I don’t want to add an additional argument name to __init__ of derivedClass b’cos in real baseClass has ten arguments instead of 2(mark,name) & if i give all them as additional argument to derivedClass I will be cluttering its argument list.

Note: I am aware of initializing baseClass using baseClass.__init__(self) or super(derivedClass, 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-05-26T20:11:55+00:00Added an answer on May 26, 2026 at 8:11 pm

    Maybe you can try something like this

    class BaseClass(object):
      def __init__(self, mark=None, name=None):   # you're using named parameters, declare them as named one.
        self.mark = mark
        self.name = name
    
    class DerivedClass(BaseClass):   # don't forget to declare inheritance
      def __init__(self, rank=None, *args, **kwargs):    # in args, kwargs, there will be all parameters you don't care, but needed for baseClass
        super(DerivedClass, self).__init__(*args, **kwargs)
        self.rank = rank 
    
    b1 = DerivedClass(name='Jibin')
    print b1.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what I'm trying to do in Python: class BaseClass: def __init__(self): print
If I've got three classes like this: class BaseClass(object): def __init__(self, base_arg, base_arg2=None): ...
Code in test.py: class Base(object): def __init__(self, l=[]): self.l = l def add(self, num):
consider the following python code class Base(object): def __init__(self): self.foo = 5 class Derived(Base):
I've defined this class: class RequiredFormSet(BaseFormSet): def __init__(self, *args, **kwargs): super(RequiredFormSet, self).__init__(*args, **kwargs) And
I have the following base class: class NeuralNetworkBase: def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs): self.inputLayer
I have a base class with a lot of __init__ arguments: class BaseClass(object): def
mod1.py import mod2 class Universe: def __init__(self): pass def answer(self): return 42 u =
What's the difference between: class Child(SomeBaseClass): def __init__(self): super(Child, self).__init__() and: class Child(SomeBaseClass): def
Given an arbitrary object: class Val(object): def __init__(self): this_val = 123 I want to

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.