# Referencing the same module from multiple files

**URL:** <https://discourse.julialang.org/t/referencing-the-same-module-from-multiple-files/77775>\
**Category:** New to Julia\
**Tags:** question, module, modules\
**Created:** [March 12, 2022, 2:44am UTC](https://discourse.julialang.org/t/referencing-the-same-module-from-multiple-files/77775 "2022-03-12T02:44:48Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 12, 2022, 3:29am UTC](https://discourse.julialang.org/t/referencing-the-same-module-from-multiple-files/77775/2 "2022-03-12T03:29:05Z")

</div>

Welcome to our community! 🎊

This problem is frequent among novice Julia programmers and was already asked multiple times in this forum. (But I concede that the search utility of Discourse **never** finds any useful results, even when I know they exist.) See:

> [@MethodError: no method matching, but the method exists](https://discourse.julialang.org/t/methoderror-no-method-matching-but-the-method-exists/54767):
>
> I’m getting the following error: ERROR: MethodError: no method matching choose(::Main.Sim.ModelBasedAgent, ::Int64) Closest candidates are: choose(::Main.Sim.ModelFreeAgent, ::Int64) at /home/xxxxx/Projects/simulateagents.jl:57 choose(::Main.Sim.ModelBasedAgent, ::Int64) at /home/xxxxx/Projects/simulateagents.jl:53 But there is a matching method. What’s going on?

> [@Dependencies of src files inside a package](https://discourse.julialang.org/t/dependencies-of-src-files-inside-a-package/43144/3):
>
> Technically, I agree with @rdeits. However, I’m not sure that’s really the solution you are looking for. My experience I have experienced the same confusion myself, and I have noticed that others seem to be stuck in the same mindset. I think it might stem from our ingrained C/C++'s include/header file methodology (assuming that’s your background). In most cases, I don’t really want to break things up into different modules - especially inside a single package. Typically, when I need to bre…

Basically, the rule is: _include **once** and import whenever necessary_.

Your topmost module should **include** all files a single time and you should use `import`/`using` relative to it (`using .MyModule` refers to a module defined in the current module, `using ..MyModule` refers to a module define in the parent module, i.e., a sibling module, and you can do something like `using ...MyModule.A.B` to go to the parent of the parent and then go down to a specific submodule). In your case, if you `include` `Useful` and `Create` inside `Calculate` you want to replace the `include("useful.jl")` inside `Create` by `import ..Useful`

---

_[View the full topic](https://discourse.julialang.org/t/referencing-the-same-module-from-multiple-files/77775)._
