# How to access global variables within a module?

**URL:** <https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859>\
**Category:** New to Julia\
**Created:** [January 21, 2019, 6:07am UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859 "2019-01-21T06:07:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 21, 2019, 6:07am UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/1 "2019-01-21T06:07:34Z")

</div>

hello, maybe a stupid one, but I failed to find relevant documents…

I have something defined in REPL (with `const`), but they’re not accessible within the functions defined within a module. What should I do?

thanks.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [January 21, 2019, 6:18am UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/2 "2019-01-21T06:18:44Z")

</div>

```julia
julia> const a = 1
1

julia> module A
           using ..Main: a
           println(a)
       end
1
Main.A

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 21, 2019, 7:23am UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/3 "2019-01-21T07:23:05Z")

</div>

Pass the variables as arguments to the functions.

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 21, 2019, 2:04pm UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/4 "2019-01-21T14:04:17Z")

</div>

wow… where is any documentation about `..Main` ???

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [January 21, 2019, 2:15pm UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/5 "2019-01-21T14:15:34Z")

</div>

[https://docs.julialang.org/en/v1/manual/modules/index.html#Standard-modules-1](https://docs.julialang.org/en/v1/manual/modules/index.html#Standard-modules-1)

[https://docs.julialang.org/en/v0.6.0/manual/modules/#Relative-and-absolute-module-paths-1](https://docs.julialang.org/en/v0.6.0/manual/modules/#Relative-and-absolute-module-paths-1)

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 21, 2019, 2:33pm UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/6 "2019-01-21T14:33:17Z")

</div>

oh, it’s about “relative module path”.

so, in your first example, why need `..` before `Main` ?

I mean, when we use `using` inside a module, normally we don’t need that `..`, and it would automatically search “outside”, right?

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [January 21, 2019, 2:42pm UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/7 "2019-01-21T14:42:45Z")

</div>

You don’t need the `..` before `Main`. I just tried it.

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 23, 2019, 5:53am UTC](https://discourse.julialang.org/t/how-to-access-global-variables-within-a-module/19859/8 "2019-01-23T05:53:50Z")

</div>

thx
