打算将自己的几个函数都放到一个文件a.jl中
module mymodule
function fun1()
pass
end
function fun2()
pass
end
end
在文件b.jl中调用a.jl的函数fun1
请问如何用简单的方式调用
目前我知道的是:
include("a.jl")
using.mymodule:fun1
不知道using后面为什么还要加个点.
在文档模块 · Julia中文文档
中也没看到有加点的用法啊
打算将自己的几个函数都放到一个文件a.jl中
module mymodule
function fun1()
pass
end
function fun2()
pass
end
end
在文件b.jl中调用a.jl的函数fun1
请问如何用简单的方式调用
目前我知道的是:
include("a.jl")
using.mymodule:fun1
不知道using后面为什么还要加个点.
在文档模块 · Julia中文文档
中也没看到有加点的用法啊
你的代码运行不了吧?
julia> module mymodule
function fun1()
1
end
function fun2()
2
end
end
Main.mymodule
julia> mymodule.fun1()
1
是运行不了,pass只是一个示意
我的意思是b.jl的文件调用a.jl文件中的函数fun1
你这个在同一个文件里面吧?
你函数名后面没有括号。。。Julia没有using后面带点的语法。请再看一遍文档。
加 .
可以表示当前module里的module,然后就不会去全局找了,我记得是这样子?我先找找文档看能不能找到
using.mymodule
→ using .mymodule
https://docs.julialang.org/en/v1/manual/modules/#Relative-and-absolute-module-paths-1
Here module
Parent
contains a submoduleUtils
, and code inParent
wants the contents ofUtils
to be visible. This is done by starting theusing
path with a period. Adding more leading periods moves up additional levels in the module hierarchy. For exampleusing ..Utils
would look forUtils
inParent
's enclosing module rather than inParent
itself.
还是我自己文档看的不仔细,谢谢两位哥们的指导,谢谢!
好的,学习了,谢谢啦!