There's a part of __import__
in Python documentation, which I don't understand:
__import__(name[, globals[, locals[, fromlist[, level]]]])
The function imports the module
name
, potentially using the givenglobals
andlocals
to determine how to interpret thename
in a package context. The standard implementation does not use itslocals
argument at all, and uses itsglobals
only to determine the package context of the import statement.
What is there to "interpret" about the module name? What is package context?
An example call using those parameters looks like this:
spam = __import__('spam', globals(), locals(), [], -1)
Why does the example provide globals()
and locals()
to the function? What happens when I only provide globals()
? Or neither?
I am probably missing some part of the namespace logic with relation to importing modules. Could you point me to an article that explains this/has examples with __import__
function?