I am initializing a class along with two subclasses in Python using a dictionary. Would it be possible to check a key in the dictionary within the init and depending the result initialize either one of the two subclasses? For instance:
Class Pet():
def __init__(self,dic):
self.name=dic['name']
self.age=dic['age']
if dic['type']=='dog':
#Initialize a dog which inherits all pet methods with name and age passed onto it
elif dic['type']=='cat':
#Initialize a dog which inherits all pet methods with name and age passed onto it
def pet_methods():
# a bunch of pet methods that I would like to be inherited
Class Dog():
def __init__(self):
self.dog_attributes=dic['dog_attributes']
Class Cat():
def __init__(self):
self.cat_attributes=dic['cat_attributes']
What code can be used in the if/else statement? Or is there a better way to organize the code? I am confused as it seems like I want to call a init within another init.