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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -