Search code examples
importmodulejuliajuno-ide

Julia: how to import a module


I'm working with the language Julia and my IDE is juno.

Now I want to import my own module. Here is an example:

First I create a module file:

module my_module
export test
function test(id, name)
  print("Your ID:", id, ". Your name: ", name)
end
end

Its path is: C:\doc\my_module.jl

Now I want to import my_module.jl into another julia project. Here is the code:

import "C:\doc\my_module.jl"

It doesn't work and I got an error:

invalid "import" statement: expected identifier

What should I do?


Solution

  • To import a module, you need to include the file then import the module.

    See the comment of @Gnimuc Key

    There are still other ways to import a module.