在Julia

时间:2019-01-14 23:25:14

标签: import module julia ijulia-notebook

我在SO上也发现了类似的问题,但似乎没有一个答案适合我的情况。

我有几个模块,在其中一个模块中,我创建了一个可变结构,希望在其他模块中使用。所有文件都处于同一级别:

  • file_module_A.jl
  • file_module_B.jl
  • file_module_C.jl

在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不起作用
  • 我不能在B和C中都使用include("./file_module_A.jl"),因为当它们相互交互时,由于include包含一个错误,因此无法将错误从Main.BA转换为Main.CA。整个代码的副本

有什么想法吗?预先感谢!

1 个答案:

答案 0 :(得分:2)

您需要使用using ..Ausing .A表示要在当前模块中查找A(在下面的示例中为B),并且您需要额外的.才能将一个模块级别提升到{{ 1}},如果您在REPL中运行示例:

Main