Here is how to import a string as a module

import sys,imp my_code = 'a = 5' mymodule = imp.new_module('mymodule') exec my_code in mymodule.__dict__ In Python 3, exec is a function, so this should work:python import sys,imp
相關文章
相關標籤/搜索