The Python documentation has a __import__ part that I don't understand:
__import__(name[, globals[, locals[, fromlist[, level]]]])
The function imports the name module, potentially using the globals and locals data to determine how to interpret name in the package context. The standard implementation does not use its locals argument at all and uses its globals only to determine the context of the import statement package.
What does it mean to “interpret” a module name? What is a package context?
An example call using these parameters is as follows:
spam = __import__('spam', globals(), locals(), [], -1)
Why does this example provide globals() and locals() functions? What happens when I provide only globals() ? Or not?
I probably missed some of the namespace logic regarding importing modules. Could you point me to an article that explains this / has examples with the __import__ function?
python import
Martin Tóth
source share