Julia 中加载/导入的包列表 [英] List of loaded/imported packages in Julia
问题描述
如何获取 Julia 会话的导入/使用包列表?
How can I get a list of imported/used packages of a Julia session?
Pkg.status()
列出所有已安装的软件包.我对通过 using ...
或 import ...
Pkg.status()
list all installed packages. I'm interested in the ones that that were imported/loaded via using ...
or import ...
似乎 whos()
包含相关信息(名称以及是否为模块).whos()
的输出能否被捕获到变量中?
It seems that whos()
contains the relevant information (the names and whether it is a module or not). Can the output of whos()
be captured in a variable?
推荐答案
using Lazy
children(m::Module) =
@>> names(m, true) map(x->m.(x)) filter(x->isa(x, Module) && x ≠ m)
children(Main)
然后会给你一个当前加载的模块列表.
children(Main)
will then give you a list of modules currently loaded.
我在这里使用 Lazy.jl 作为画眉宏 (@>>
),但您可以轻松地重写它:
I used Lazy.jl here for the thrush macro (@>>
), but you can rewrite it without easily enough:
children(m::Module) =
filter(x->isa(x, Module) && x ≠ m, map(x->m.(x), names(m, true)))
或者,您可以添加 &&x ≠ Lazy
到 filter
以避免包含它.
Alternatively you could add && x ≠ Lazy
to the filter
to avoid including it.
这篇关于Julia 中加载/导入的包列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!