3中所有导入的列表

3中所有导入的列表

本文介绍了python 3中所有导入的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过程序查找python 3中所有可用导入的列表?我一开始尝试了这个,但无法理解它返回的内容

How to find out list of all available imports in python 3 via program? I tried this at first, but couldn't understand what it returned

import sys
    sys.modules

我认为这不是方法,尽管这首先是我的想法。我搜索了网页,发现了这个

I think this isn't the way, although this struck my mind first. I searched the web and found this http://effbot.org/librarybook/core-modules-index.htm

有人可以告诉我这是否正确吗?

Can someone tell me whether this is correct or not?

推荐答案

来自(在python stdlib上查找文档的好地方)

From http://docs.python.org/library/sys.html (a good place to look for documentation on python stdlib)

是一个字符串的元组(有点像不可变的匿名结构),给
编译成这个Python
解释器的所有模块的名称。

is a tuple (a bit like a immutable anonymous structs) of strings giving the names of all modules that are compiled into this Python interpreter.

sys.modules

这是一个将模块名称映射到模块的字典(模块对象)已经加载的
。这可以被操纵以强制
重新加载模块和其他技巧。请注意,从此字典中删除模块
与在
对应的模块对象上调用 reload()不同。

This is a dictionary that maps module names to modules (module objects) which have already been loaded. This can be manipulated to force reloading of modules and other tricks. Note that removing a module from this dictionary is not the same as calling reload() on the corresponding module object.

因此模块是一个字典(模块名称到实际模块对象的映射)。要获得名称类型 sys.modules.keys()尽管它可能没那么有用。

So modules is a dictionary (a mapping of module names to the actual module objects). To get just the names type sys.modules.keys() although it probably isn't that usefull.

这篇关于python 3中所有导入的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:20