What is the equivalent of import *
in Python using functions (presumably from importlib
)?
I know that you can import a module with mod = __import__(...)
, which will delegate to whatever the currently configured implementation is. You can also do something like
mod_spec = importlib.utl.spec_from_file_location(...)
mod = importlib.util.module_from_spec(mod_spec)
mod_spec.loader.exec_module(mod)
which allows you to do crazy things like injecting things into the module by inserting them before the call to exec_module
. (Courtesy of https://stackoverflow.com/a/67692/2988730 and https://stackoverflow.com/a/38650878/2988730)
However, my question remains. How does import *
work in function form? What function determines which names to load from a module depending on the presence/contents of __all__
?