获取 python 中导入模块的有序列表
Get an ordered list of imported modules in python
有没有办法获取列为导入的导入模块列表?
globals()
returns 一个无序的字典。
尽管不能保证字典在 CPython-3.6 中是有序的它在当前的 CPython 3.6 版本中是有序的。
因此,如果您显示 sys.modules
(包含所有已加载模块的字典),则应按 "relative order of imports":
排序
import sys
print(list(sys.modules))
有没有办法获取列为导入的导入模块列表?
globals()
returns 一个无序的字典。
尽管不能保证字典在 CPython-3.6 中是有序的它在当前的 CPython 3.6 版本中是有序的。
因此,如果您显示 sys.modules
(包含所有已加载模块的字典),则应按 "relative order of imports":
import sys
print(list(sys.modules))