Injecting a variable into the name space of a module

The script demo.py imports the module testMod. The function load_var() is part of testMod. It injects the variable a into the name space of demo. load_var() modifies the dictionary of varibles that are local to demo. The dictionary is passed as an argument. (Eugen Wintersbergers brilliant idea is acknowledged).

#!/usr/bin/env python
#
# file demo.py
#
from testMod import *

load_var( locals())

print( "a=",a)

The file testMod.py contains the function load_var() that injects the variable a into the name space of demo.

#!/usr/bin/env python
#

def load_var( d):
	d['a'] = 12

if __name__ == "__main__":
	pass