I want to automate the creation of objects for all child classes of a parent class.For example: This is the parent class
from abc import ABC,abstractmethod
class Parent(ABC):
@abstractmethod
def fetch(self):
# some code here
Now I create child classes for this parent class
#child classes
class obj1(Parent):
def fetch(self):
# some code
class obj2(Parent):
def fetch(self):
# some code
class obj3(Parent):
def fetch(self):
# some code
Now my problem is I want to create one object for all these children classed here automatically and save them in an objectList.So that even if someone creates a new child class later, the code will automatically create an object for that new child class and append it in the objectList.
I can do this manually by:
objectList = []
objectList.append(obj1())
objectList.append(obj2())
objectList.append(obj3())
But if someone creates a new child for example obj4() I have to manually append obj4. How to create an object of all child classes automatically?