【问题标题】:List loaded IPython extensions列出加载的 IPython 扩展
【发布时间】:2020-10-04 20:50:15
【问题描述】:

有没有办法获取当前加载的 IPython 扩展的列表?

例如,如果我使用 %load_ext autoreload 或通过运行将扩展自动重载加载到 IPython 中:

from IPython import get_ipython
ipython = get_ipython()
ipython.magic("%load_ext autoreload")

有什么方法可以证明我已经加载了这个扩展?

我已经尝试过通过直接访问输入历史记录来实现这一点

from IPython import get_ipython
ipython = get_ipython()
hist = ipython.extract_input_lines("0:100")

但事实证明,IPython 不会在此处或通过In_ih 访问的历史列表中存储带有魔术函数的输入。似乎只保存了执行普通 Python 的行。

无论如何,这种方案一般都行不通。如果使用runfile 调用的脚本运行load_ext,那么历史上将出现的所有内容都类似于runfile('script_name.py', wdir='path/to/wdir')

【问题讨论】:

    标签: python ipython


    【解决方案1】:

    通过查看%load_ext 代码发现了这一点:

    from IPython import get_ipython
    ip = get_ipython()
    ip.extension_manager.loaded
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2014-02-27
      相关资源
      最近更新 更多