python - Importing modules globally -


i provide users python script import modules them , drop python interpreter imported modules available @ level. have code thought might work, not seem to:

module_list = ['module_a','module_b']  # import our common modules module in module_list: try:     print "importing: {0}".format(module)     exec("import {0}".format(module)) except:     print "fyi failed importing {0}. not available use".format(module)               

so when script done drop python module user can do:

>>> module_a.run() 

you can use code.interactiveconsole() , pass locals dictionary containing local context in console run. storing modules in there can make them available interactive shell.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -