# How to use multiple levels of module?

**URL:** <https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 15, 2017, 2:15am UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899 "2017-09-15T02:15:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)\
**Post date:** [September 15, 2017, 2:15am UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/1 "2017-09-15T02:15:43Z")

</div>

suppose that we have a module hierarchy of Foo.Bar.XX, and Foo.YY  
in the XX module, how can I use YY module?  
I tried these two, do not work  
using …/…YY  
using …YY

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 15, 2017, 2:47am UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/2 "2017-09-15T02:47:37Z")

</div>

Can you please write some code with the modules so that we can try answer the question properly?

---

<div class="post-metadata">

**Author:** ![merl-dev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/merl-dev/32/96_2.png) [@merl-dev](https://discourse.julialang.org/u/merl-dev)\
**Post date:** [September 15, 2017, 5:10am UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/3 "2017-09-15T05:10:24Z")

</div>

> <https://github.com/JuliaLang/julia/issues/3312>
>
> I might be ignorant of the scope rules for submodules, but why does this:
> 
> \`\`\` j…ulia
> module Amod
> type A
> end
> 
> type B
> a::A
> end
> end
> \`\`\`
> 
> work, while this:
> 
> \`\`\` julia
> module Amod
> type A
> end
> 
> module Bmod
> type B
> a::A
> end
> end
> end
> \`\`\`
> 
> gives \`ERROR: A not defined\`?

> <https://stackoverflow.com/questions/40310787/julia-code-encapsulation-is-this-a-generally-good-idea/40314833#40314833>

> [@Scope of submodules](https://discourse.julialang.org/t/scope-of-submodules/2806):
>
> Say I have a module A, in which I define a constant. I would like to be able to use that constant in submodules of that module: module A a = 2 module B f(x) = x\*a end module C g(x) = x\*a end end This does not work: A.B.f(3) UndefVarError: a not defined Clearly, I need to import a into each submodule, but that seems a bit annoying… Would there be a way to automatically inherit from the superscope, possibly with a submodule keyword?

---

<div class="post-metadata">

**Author:** ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)\
**Post date:** [September 15, 2017, 2:01pm UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/4 "2017-09-15T14:01:56Z")

</div>

This test code works, but the same way do not work in my project…

```julia
module C                                                                                                              
 end                                                                                                                   
                                                                                                                       
 module A                                                                                                              
 module B                                                                                                              
 using ....C                                                                                                           
 end                                                                                                                   
 end         

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 15, 2017, 4:18pm UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/5 "2017-09-15T16:18:36Z")

</div>

Then the issue is somewhere else in your project? Try to comment out the code until you get something that works. The syntax is correct, you can do

```julia
using C

```

or

```julia
using ....C

```

in this case because the module `C` is at the top level (i.e. `Main.C`).

---

<div class="post-metadata">

**Author:** ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)\
**Post date:** [September 15, 2017, 5:04pm UTC](https://discourse.julialang.org/t/how-to-use-multiple-levels-of-module/5899/6 "2017-09-15T17:04:11Z")

</div>

Thanks, I’ll just use the Main.C approach for now. It works.
