【问题标题】:Check the modules imported into an interactive console [duplicate]检查导入到交互式控制台的模块[重复]
【发布时间】:2018-10-31 18:09:17
【问题描述】:

我正在 Ipython 中进行测试,并希望确认已导入的模块和包,

首先我尝试了localsglobals

In [22]: len(globals())
Out[22]: 46

In [23]: len(locals())
Out[23]: 48

我必须手动查找。

如何将导入的模块单独列出?

【问题讨论】:

    标签: python


    【解决方案1】:

    以下代码有效

    import sys
    print([i for i in globals() if i in sys.modules.keys()])
    

    【讨论】:

      【解决方案2】:

      我想你想要的只是:

      print(dir())
      

      例如

      Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
      [GCC 7.3.0] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> print(dir())
      ['__builtins__', '__doc__', '__name__', '__package__']
      >>> import csv
      >>> import json
      >>> print(dir())
      ['__builtins__', '__doc__', '__name__', '__package__', 'csv', 'json']
      >>> 
      

      【讨论】:

      • 他提到,他想专门了解导入的模块。这给出了详尽的清单
      猜你喜欢
      • 2010-11-06
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 2011-05-31
      • 2016-04-05
      相关资源
      最近更新 更多