Say I've imported a package by doing import package
. In each of the modules within this package, there is a function called "func". Is there a way to iterate over the modules that were imported with this package, calling the function for each module?
Something along the lines of this pseudocode:
import package
for module in package:
module.func()
EDIT: solution
import inspect
import package
for name, module in inspect.getmembers(package, predicate=inspect.ismodule):
module.func()
Now it is also required that you filter out the built in modules that are returned and don't contain func implementations, but that is a separate problem altogether.