python - 列出加载的 IPython 扩展
问题描述
有没有办法获取当前加载的 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
run调用load_ext
,历史上会看到的都是runfile('script_name.py', wdir='path/to/wdir')
.
解决方案
通过查看%load_ext
代码来解决这个问题:
from IPython import get_ipython
ip = get_ipython()
ip.extension_manager.loaded
推荐阅读
- c - 丰富数字的程序 <=k
- reactjs - 在 yarn.lock 中发现 serialize-javascript 漏洞
- algorithm - Kotlin 将长字符串字母转换为数字 id
- entity-framework - 使用 Entity Framework Core 执行原始 sql
- javascript - 为什么 readdirSync() 说没有这样的文件或目录?
- swift - 函数声明了一个不透明的返回类型,但其主体中的返回语句没有匹配的底层类型
- java - 在 JavaCV 中对 FFmpegFrameGrabber 调用 setFrameNumber() 后出现“错误的 src 图像指针”错误
- typescript - 为 monorepo 扩展“路径”tsconfig 文件
- r - R:在逐列更改前后值的基础上找到最小值
- c# - 我的缓慢修复脚本变得越来越快(C#/Unity)