0

Is it possible to inherit a class and use its init function without declaring all parameters again in the child class?

I have a class with lots of parameters, but I don't want to use a list (**args). I wouldn't see my actual parameters:

class Table(object):
    def __init_(self, name, height ...):
        self.name = name
        self.height = height

class RoundTable(Table):
    def __init__(self, radius):
        self.radius = radius

table = RoundTable(name = "Placeholder",
                   height = 10,
                   radius = 20)

1 Answer 1

1

Use the super class before assigning specfic args

def __init__(self,radius,*args,**kwargs):
     super().__init__(*args,**kwargs)
     self.radius = radius

Edit : I'm assuming you mean class and not a function

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.