导入的模块只是变量-名称绑定到某些值。因此,您所需要做的就是导入它们,并使用
global关键字使它们成为全局的。
例:
>>> mathTraceback (most recent call last): File "<stdin>", line 1, in <module>NameError: name 'math' is not defined>>> def f():... global math... import math...>>> f()>>> math<module 'math' from '/usr/local/lib/python2.6/lib-dynload/math.so'>



