DEV Community

Lam Nguyen
Lam Nguyen

Posted on

Answer: How to get reference to module by string name and call its method by string name?

To get the module, you can use globals. To get the function, use getattr:

getattr(globals()[module_name], function_name)

Importing a module just binds the module object to a name in whatever namespace you import it in. In the usual case where you import at the top level of the module…

Top comments (0)