【问题标题】:Python: what modules have been imported in my process?Python:我的流程中导入了哪些模块?
【发布时间】:2010-06-06 23:53:16
【问题描述】:

如何获取已导入进程的模块列表?

【问题讨论】:

    标签: python python-module


    【解决方案1】:

    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
    >>>
    

    【讨论】:

      【解决方案2】:

      如果您只想查看导入的模块(以及导入的顺序),也可以使用 -v 选项运行解释器

      【讨论】:

        猜你喜欢
        • 2018-02-26
        • 1970-01-01
        • 2021-11-23
        • 2018-01-22
        • 2018-10-06
        • 2012-05-27
        • 2010-10-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多