Skip to content Skip to sidebar Skip to footer

How To Call Parent Class Init With Default Values From Child Class?

I am trying to give my subclasses default variables and stop duplicating code as the file is getting fat: class Base(object): def __init__(self, username=None, password=None,

Solution 1:

You have to pass the arguments from the SubClass init to the init block of Base:

classSubclass(Base):def__init__(self, username="hoss_it87", password="whatsgoodSO", start_url="www.boss-sauce.com"):
        super(Subclass, self).__init__(username=username, password=password, start_url=start_url)

In your code, the Base init is called without arguments and thus takes its default arguments, which are all None.

Post a Comment for "How To Call Parent Class Init With Default Values From Child Class?"