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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With