我想爲用戶提供一個python腳本,可以爲它們導入一些模塊,然後通過導入的模塊下載到python解釋器。我有一些代碼,我想可能會奏效,但它似乎並不:全局導入模塊
module_list = ['module_a','module_b']
# Import our common modules
for module in module_list:
try:
print "Importing: {0}".format(module)
exec("import {0}".format(module))
except:
print "FYI we failed importing {0}. It will not be available for you to use".format(module)
所以當腳本完成,將下降到Python模塊,用戶可以做到:
>>> module_a.run()
你有沒有考慮過使用IPython的殼呢?它更加舒適,它確實支持嵌入。 – ThiefMaster 2013-04-18 06:18:23