我在SO上也发现了类似的问题,但似乎没有一个答案适合我的情况。
我有几个模块,在其中一个模块中,我创建了一个可变结构,希望在其他模块中使用。所有文件都处于同一级别:
在file_module_A.jl中:
module A
mutable struct MyType
variable
end
end
在file_module_B.jl中:
module B
# I need to import MyType here
end
在file_module_C.jl中:
module C
# I need to import MyType here
end
我尝试了以下失败的尝试:
using .A
不起作用include("./file_module_A.jl")
,因为当它们相互交互时,由于include
包含一个错误,因此无法将错误从Main.BA转换为Main.CA。整个代码的副本有什么想法吗?预先感谢!
答案 0 :(得分:2)
您需要使用using ..A
。 using .A
表示要在当前模块中查找A
(在下面的示例中为B
),并且您需要额外的.
才能将一个模块级别提升到{{ 1}},如果您在REPL中运行示例:
Main