I have a folder structure like this:
package_name/
|-- module1
|-- module2
|-- module3
What I need to do is import package_name, and then iterate over each of the modules, running code upon them one after another. The import is given at the command line, so I can’t control that ahead of time. So a user might say, run_script.py --modules='package_name.module1' or the user might simply say, run_script.py --modules='package_name.
I can do from package_name import *, and that will import everything defined in my __all__ variable in __init__.py, but from there I’m a bit stumped.
For my next step, I need a way of doing:
for module in imported:
module.run()
I usually use a function like this to import a module by path:
Use like this:
Or in your case: