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__
Just call the parent's __init__
using super
:
class inheritedclass(initialclass):
def __new__(self):
self.attr3 = 'three'
super(initialclass, self).__init__()
I strongly advise to follow Python's naming conventions and start a class with a Capital letter, e.g. InheritedClass
and InitialClass
. This helps quickly distinguish classes from methods and variables.