I need to import two modules (determined at runtime) in the same package and I was wondering if it could be done with one import_module
command.
Basically, I want the equivalent of
from some_package import module1, module2
Ways I could do it:
import_module
once for each module__init__.py
import the two modules, then import the package__import__
, but this doesn't use importlib
and is discouraged by the docs.There are probably more ways to do it than this. Can it be done with a single call to import_module
? Failing that, is there a way to do this that is considered the standard way?
One call? Probably not. You can however do:
for module in modules:
importlib.import_module(module)
or:
map(importlib.import_module, module)
Why does it matter if it's more than one call? The internal implementation of all the ways to import is probably serial and individual 'calls' either way.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments