Skip to main content
 首页 » 编程设计

python之如何列出 ipython session 中加载的所有名称

2025年05月04日13落叶

我通过将一些 *.py 文件放入 ~/.ipython/profile_default/startup 来将变量和函数注入(inject)我的默认 ipython 命名空间。

我可以通过键入 %who 或 %who_ls 列出在 ipython session 中新创建的名称。但是,我的启动文件中定义的名称没有显示出来。是否有神奇的功能或方法可以将启动目录中引入的所有名称列出到事件的 ipython 交互式 session 中?

请您参考如下方法:

您可以通过 %psearch 使用模式搜索.要列出不在内置空间中的所有对象,请使用:

%psearch -e builtin * 

%psearch [options] PATTERN [OBJECT TYPE]

Note: ? can be used as a synonym for %psearch, at the beginning or at the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the rest of the command line must be unchanged (options come first), so for example the following forms are equivalent

%psearch -i a* function -i a* function? ?-i a* function