I have set of tasks directory which has multiple tasks file like task1.py
, task2.py
every task has different class say Task1
in task1.py and bunch of other dependent class, imports and this directory has some other files as well.
I want to create a mapping of this filename and the class object at runtime. What are the options do I have.
Adding base code
task_dict = {} # filename: task_object
def get_class_name():
# Here I will do walk through tasks directory and
# find all the files that has task defined in it
# and create a mapping which is like
# {"task1": Task1, "task2": Task2}
task1.py will look like
import statements
Class Task1(CanInheritSomething):
# some Code
class BunchOfOtherClass:
pass
def some_random_method:
pass
It's same for task2.
My question is what type of identification can be used to import Task1 class at runtime. I am still designing it so I am open with options