python - Loading modules at runtime from functions -


i load modules @ runtime.

if works:

a = __import__('datetime',globals(),locals(),[],-1)  e in a.__dict__:     if not e.startswith("__"):         globals()[e] = a.__dict__[e] 

but if try doesn't work:

def module_loader(modname,g,l):     = __import__(modname,g(),l(),[],-1)      e in a.__dict__:         if not e.startswith("__"):             g()[e] = a.__dict__[e]   module_loader('datetime',globals,locals) 

any help?

your snippet above works me if call as

module_loader('datetime', globals, locals) 

Comments