3
如何获取已导入到我的过程中的模块列表?Python:在我的过程中导入了哪些模块?
如何获取已导入到我的过程中的模块列表?Python:在我的过程中导入了哪些模块?
sys.modules.values()
...如果你真的需要的模块的名,使用sys.modules.keys()
dir()
是不是你想要的。
>>> import re
>>> def foo():
... import csv
... fubar = 0
... print dir()
...
>>> foo()
['csv', 'fubar'] # 're' is not in the current scope
>>>
您也可以运行与-v
选项的解释,如果你只是想看看那些进口的模块(和它们进口的顺序)