# Is "import" required for user-defined modules?

**URL:** <https://discourse.julialang.org/t/is-import-required-for-user-defined-modules/57352>\
**Category:** New to Julia\
**Created:** [March 17, 2021, 1:37am UTC](https://discourse.julialang.org/t/is-import-required-for-user-defined-modules/57352 "2021-03-17T01:37:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterB](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@PeterB](https://discourse.julialang.org/u/PeterB)\
**Post date:** [March 17, 2021, 1:37am UTC](https://discourse.julialang.org/t/is-import-required-for-user-defined-modules/57352/1 "2021-03-17T01:37:01Z")

</div>

When using modules, is “import” or “using” needed? The reason I ask is that in the following toy example, according to my reading of the documentation, an “import” (or “using”) statement is required. But the program runs whether or not the “import” statement is commented. Why?

And assuming it is not needed, is it bad practice for me to make a habit of not using it?

```julia
module ex1mod

using Printf

function printsquare(x)
    @printf("%g^2 = %g\n", x, x^2)
end

end # module ex1mod

#import ex1mod # not needed!

ex1mod.printsquare(2)

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 17, 2021, 1:41am UTC](https://discourse.julialang.org/t/is-import-required-for-user-defined-modules/57352/2 "2021-03-17T01:41:36Z")

</div>

you don’t need it in this case because the module is evaluated in the same scope.

```julia
julia> include("test.jl") #without your last line
Main.ex1mod

```

So `ex1mod.printsquare` is in fact `Main.ex1mod.printsquare`.  
(`include` is equivalent to pasting those lines in REPL directly).

You will need it if your `ex1mod` is an actual package because otherwise Julia will not know what `ex1mod` is. You can think of `import X` as finding where / which version of X and then `include(X.jl)`

---

<div class="post-metadata">

**Author:** ![PeterB](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@PeterB](https://discourse.julialang.org/u/PeterB)\
**Post date:** [March 17, 2021, 2:20am UTC](https://discourse.julialang.org/t/is-import-required-for-user-defined-modules/57352/3 "2021-03-17T02:20:16Z")

</div>

Thank you. But (at least) 99.9% of all software I have ever written (not just in Julia) has been for personal or internal company/department use. So it seems to me that, for the average user, the advice should be to not worry about using “import” and “using” for loading your own modules, or using “export” inside your modules, unless intending to make it into a package.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 18, 2021, 2:51pm UTC](https://discourse.julialang.org/t/is-import-required-for-user-defined-modules/57352/4 "2021-03-18T14:51:38Z")

</div>

> [@PeterB](#):
>
> for the average user, the advice should be to not worry about using “import” and “using” for loading your own modules, or using “export” inside your modules, unless intending to make it into a package

On the contrary, since packages are so lightweight and easier to manage as a coherent unit (think: CI, versioning, etc), code should just be organized into packages, even if used internally/locally.
