4

I am asking this question because every single other page on SO I've Googled on the subject seems to devolve into overly simple cases or random discussions on details beyond the scope.

class Base: def __init__(self, arg1, arg2, arg3, arg4): self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 self.arg4 = arg4 class Child(Base): def __init__(self, arg1, arg2, arg3, arg4, arg5): super(Child).__init__(arg1, arg2, arg3, arg4) self.arg5 = arg5 

This is what I've tried. I get told that I need to use a type and not a classobj, but I don't know what that means and Google isn't helping.

I just want it to work. What is the correct practice in doing so in Python 2.7?

0

1 Answer 1

8

Your base class must inherit from object (new style class) and the call to super should be super(Child, self).

You should also not pass arg5 to Base's __init__.

class Base(object): def __init__(self, arg1, arg2, arg3, arg4): self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 self.arg4 = arg4 class Child(Base): def __init__(self, arg1, arg2, arg3, arg4, arg5): super(Child, self).__init__(arg1, arg2, arg3, arg4) self.arg5 = arg5 
Sign up to request clarification or add additional context in comments.

3 Comments

What if the base class weren't inheriting from object?
No I mean how did people do it old style?
@user6596353 With the class name, but that isn't a recommended approach: Base.__init__(arg1, arg2, arg3, arg4)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.