导入具有不同名称的Julia模块

问题描述 投票:4回答:1

在Python中,您可以使用as关键字导入具有您想要的任何名称的模块。朱莉娅有同样的东西吗?

显然你可以做到

import moduleWithReallyLongName
M = moduleWithReallyLongName

有没有更好的办法?

julia
1个回答
8
投票
import moduleWithReallyLongName
const M = moduleWithReallyLongName

请注意const的用法。根据经验,Julia中的任何全局变量都应该是类型稳定的,否则您将观察到性能降低。

另一个选择是包ImportMacros.jlhttps://github.com/fredrikekre/ImportMacros.jl

using ImportMacros
@import moduleWithReallyLongName as M
© www.soinside.com 2019 - 2024. All rights reserved.