Source From Here
In python, I have to instantiate certain class, knowing its name in a string, but this class 'lives' in a dynamically imported module. How to do it?
You can use getattr to access the attributes of loaded module. Consider you have module below:
To access the module my_mod and create object of class MyClass dynamically:
Or you can leverage another package importlib: