# \`import \<module\>\` makes all objects available without prefix

**URL:** https://discourse.julialang.org/t/import-module-makes-all-objects-available-without-prefix/110931
**Category:** General Usage
**Tags:** question
**Created:** [February 29, 2024, 4:16am UTC](https://discourse.julialang.org/t/import-module-makes-all-objects-available-without-prefix/110931 "2024-02-29T04:16:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![suiato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suiato/32/1713_2.png) [@suiato](https://discourse.julialang.org/u/suiato)
#### Post date: [February 29, 2024, 4:16am UTC](https://discourse.julialang.org/t/import-module-makes-all-objects-available-without-prefix/110931/1 "2024-02-29T04:16:24Z")

</div>

I have a simple question: what is `import <module>` supposed to do?  
Say, a module A.jl is

```julia
module A
export sayA

function sayA()
    println("This is A.")
end
end

```

and, test.jl is

```julia
import A
sayA()

```

They are in the same directory, and the directory is added to LOAD\_PATH via startup.jl. Running `include("test.jl")` in a terminal results in

```julia
This is A.

```

Is this expected?  
I thought I had to do `import A : sayA` in test.jl.

If I replace `import A` with `import A : sayA` in test.jl, I get the error:

```julia
ERROR: LoadError: MethodError: no method matching (::Colon)(::Nothing, ::typeof(sayA))
...

```

When I replace `import` with `using`, the results are the same. Then, no difference between `import` and `using` 😮

Is this normal, or is something wrong with my understanding or my Julia environment? I use Julia Version 1.10.1 (2024-02-13) and VScode on Windows 11.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [February 29, 2024, 7:13am UTC](https://discourse.julialang.org/t/import-module-makes-all-objects-available-without-prefix/110931/2 "2024-02-29T07:13:21Z")

</div>

> [@suiato](#):
>
> include(“test.jl”)

I cannot reproduce. I get

```julia-repl
julia> include("test.jl")
ERROR" LoadError: UndefVarError: `sayA` not defined

```

> [@suiato](#):
>
> If I replace `import A` to `import A : sayA` in test.jl, I get the error:

There should not be a space between the A and colon.

```julia-repl
julia> import A : sayA
ERORR: UndefVarError: `sayA` not defined

julia> import A: sayA

```

What is in your startup.jl ? Try starting Julia with `--startup-file=no`.

---

<div class="post-metadata">

### Author: ![suiato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suiato/32/1713_2.png) [@suiato](https://discourse.julialang.org/u/suiato)
#### Post date: [February 29, 2024, 5:09pm UTC](https://discourse.julialang.org/t/import-module-makes-all-objects-available-without-prefix/110931/3 "2024-02-29T17:09:07Z")

</div>

Thank you, mkitti.  
I tried `julia --startup-file=no`, but I got

```julia
julia> julia --startup-file=no
ERROR: ParseError:
# Error @ REPL[2]:1:7
julia --startup-file=no
# └┘ ── invalid operator
Stacktrace:
 [1] top-level scope
   @ none:1

```

My `startup.jl` file is like

```julia
using Revise
Revise.includet("C:/...Config.jl")
Revise.includet("C:/...Types.jl")
push!(LOAD_PATH, "C:/...Projects/mlp/src")

```

> There should not be a space between the A and colon.

Oh, that made it work! Thanks 🙂  
It resolves the error part of my question.

I still wonder why

```julia
import A
sayA()

```

in test.jl works in my case, while it doesn’t in your case. I understand it shouldn’t.

---

<div class="post-metadata">

### Author: ![suiato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suiato/32/1713_2.png) [@suiato](https://discourse.julialang.org/u/suiato)
#### Post date: [February 29, 2024, 6:17pm UTC](https://discourse.julialang.org/t/import-module-makes-all-objects-available-without-prefix/110931/4 "2024-02-29T18:17:00Z")

</div>

The remaining problem is resolved:  
I commented out the lines in startup.jl except the line for `push!(LOAD_PATH,...)`, created C.jl, modified test.jl to import the C module, and started a new Julia session. When I ran tests.jl, it failed correctly 🙂

It seems starting a new Julia session was the answer. I put the lines I commented out in the startup.jl back, and test.jl ran correctly in that situation.
