简体   繁体   English

查找导入的Python模块

[英]Find Imported Python Modules

I'm building a flask application and I want to remove the redundancy on importing modules. 我正在构建一个烧瓶应用程序,我想删除导入模块的冗余。 So, on runtime I want to print all the imported modules. 所以,在运行时我想打印所有导入的模块。

Is there a way to do that? 有没有办法做到这一点?

import sys
print(sys.modules.keys())

sys.modules

docs 文档

"This is a dictionary that maps module names to modules which have already been loaded." “这是一个将模块名称映射到已经加载的模块的字典。”

您可以使用sys.modules.keys()但您需要导入sys才能使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM