How can I import a module in another module in same file in julia ??
Please kindly read the documentation.
I actually read.
But I wanted to know that , is there a way to import module a in moduleb without using include.
The very first example in the section I linked is about this.
Also, please post quoted code.
In that example module Parent
contains module Utils
so we can use using
for importing Utils
directly . But In my example module b
does not contain module a
but are in same file new.jl
so if I use using .a
it does not work.
Why not just wrap both modules in a module? A .jl file usually contains one module, but that module can have multiple submodules.
PS: Module names are usually uppercase.
@anon67531922 are you asking to make a new module
(say C) which contains both the module or nesting module A
inside module B
(like in example given in documentation)???
Either way would be fine. It is up to you
From your question, it seems you don’t want them nested so you could do something like:
module C
module A
end
module B
using ..A
end
end
Thanks a lot @anon67531922 , It worked perfect.
This should really be expanded to explicitly handle multiple files:
#lemon.jl
module Lemon
squeeze()
end
#lime.jl
include("lemon.jl")
module Lime
import ..Lemon
function test()
Lemon.squeeze()
end
end
To reiterate: include(“lemon.jl”) appends the contents of lemon.jl to the current namespace (lime.jl), resulting in
#lime.jl
module Lime
import ..Lemon
function test()
Lemon.squeeze()
end
end
module Lemon
squeeze()
end
With lemon included, you should use the relative import (import …Lemon) as mentioned in the documentation.