4

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?

Yves
  • 11,597
  • 17
  • 83
  • 180

1 Answers1

4

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.

Dmitry Mottl
  • 842
  • 10
  • 17
Yves
  • 11,597
  • 17
  • 83
  • 180
  • this is correct but misleading because is not mandatory for a module to first `include` then `import`, and after that, it's @Gnimuc answer, you can check the **community wiki** before sending another's answer. – Reza Afzalan Nov 10 '15 at 15:01
  • @Thomas i put it as a comment because that works only for your specific case. in fact, there are several ways to import a module in julia depending on your use case, e.g. as @Reza mentioned above: add the path into `LOAD_PATH`. so you can edit your incorrect answer and give it fuller explanation. i'll definitely upvote it :) – Gnimuc Nov 10 '15 at 16:31
  • @GnimucKey :D Well I just need to import a module dynamically so your method is enough. thanks. – Yves Nov 10 '15 at 16:58