As the docs explain, the globals parameter on __import__ does not "add" additional globals to the imported module, as you seem to believe - indeed, that globals() the import module usually goes there, so such an injection would be very problematic if this happened . Indeed, __import__ docs specifically say:
The standard implementation does not generally use the argument of its local residents and uses its global values only to determine the context of the packaging import statement.
Edit : if you need an injection, for example. into an empty imported module, as suggested by OP in the comment, it’s easy if you are fine by executing immediately after import:
themod = __import__(themodname) themod.__dict__.update(thedict)
The imported body module will not know about the continuation of the injections, but this is clear, regardless of whether the specified body is empty anyway ;-). Immediately after import, you can enter the contents of your heart, and all subsequent applications of this module will see your injections as if they were bona fide names at the module level (because they are :-).
You could even, if you want, save the need for an empty .py module to start with ...:
import new, sys themod = new.module(themodname) sys.modules[themodname] = themod themod.__dict__.update(thedict)
Edit : OP is trying to clarify in editing Q ...:
I think my real question is: how do I introduce global functions / variables into an imported module before the module works ...?
"The module starts" does not make much sense ", the modules are loaded (which their body executes), only once (unless re- loaded explicitly later) ... they never" start "" as such. Given an empty module, you first import it (which has not done anything since the empty module), then you can, if you want to use a combination of themodule.__dict__.update and attribute assignment to populate the module - the function is not automatically called when it is just mentioned (because The OP expresses concerns that they will be in the commentary), so they can be treated like any other variable in this regard (and most others, so Python said it has first class ).