I would like to give a daughter class some extra attributes without having to explicitly call a new method. So is there a way of giving the inherited class an __init__
First of all you're mixing __init__
and __new__
, they are different things. __new__
doesn't take instance (self
) as argument, it takes class (cls
).
As for the main part of your question, what you have to do is use super
to invoke superclass' __init__
.
Your code should look like this:
class initialclass(object):
def __init__(self):
self.attr1 = 'one'
self.attr2 = 'two'
class inheritedclass(initialclass):
def __init__(self):
self.attr3 = 'three'
super(inheritedclass, self).__init__()