# Scope when using multiple modules

**URL:** <https://discourse.julialang.org/t/scope-when-using-multiple-modules/32344>\
**Category:** New to Julia\
**Created:** [December 16, 2019, 6:03pm UTC](https://discourse.julialang.org/t/scope-when-using-multiple-modules/32344 "2019-12-16T18:03:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![urp](https://avatars.discourse-cdn.com/v4/letter/u/b38774/32.png) [@urp](https://discourse.julialang.org/u/urp)\
**Post date:** [December 16, 2019, 6:03pm UTC](https://discourse.julialang.org/t/scope-when-using-multiple-modules/32344/1 "2019-12-16T18:03:48Z")

</div>

I am new at using Julia. I am writing a PDE solver. I would like to have a struct that stores all mesh/simulation variables that could then be accessed from other modules in my code. However, I am having some trouble with the result (due to issues related to scope of variables):  
Here is the simplified code to mimic the issue:

I have three files: MyParams.jl, ModuleA.jl main.jl,

## --------------- MyParams.jl -------------------- module MyParams param\_A = end

---------------ModuleA.jl------------------------  
module ModuleA  
include(“MyParams.jl”)

function Set\_Param\_A(N)  
push!(MyParams.param\_A, N);  
println("In ModuleA, size of param\_A: ", length(MyParams.param\_A));  
end

## end

--------------main.jl---------------------------  
include(“ModuleA.jl”)  
include(“MyParams.jl”)

## ModuleA.Set\_Param\_A(10); println("In main, size of param\_A: ", length(MyParams.param\_A));

My output is:  
In ModuleA, size of param\_A: 1  
In main, size of param\_A: 0

Two questions:

- Why is size of param\_A not 1, when accessed from main?
- What is the best way to store simulation parameters/mesh that needs to be accessed and modified from other modules?

Thanks

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [December 16, 2019, 9:58pm UTC](https://discourse.julialang.org/t/scope-when-using-multiple-modules/32344/2 "2019-12-16T21:58:16Z")

</div>

When you include a file inside a module definition, all the contents of that file is loaded into the module scope. So, you have modules `Main.ModuleA.MyParams` and `Main.MyParams`, which the system considers different.

There have been discussions recently on how to organize code in such cases, you may find and try different suggestions to choose from:  
([Writing functions for types defined in another module](https://discourse.julialang.org/t/writing-functions-for-types-defined-in-another-module/31895))  
([What is the preferred way to use multiple files?](https://discourse.julialang.org/t/what-is-the-preferred-way-to-use-multiple-files/30687))

Also, please see this topic ([Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)) for tips on formatting.

---

<div class="post-metadata">

**Author:** ![urp](https://avatars.discourse-cdn.com/v4/letter/u/b38774/32.png) [@urp](https://discourse.julialang.org/u/urp)\
**Post date:** [December 18, 2019, 5:00pm UTC](https://discourse.julialang.org/t/scope-when-using-multiple-modules/32344/3 "2019-12-18T17:00:17Z")

</div>

Thank you for your help!
