# Importing constant definition from a module file

**URL:** <https://discourse.julialang.org/t/importing-constant-definition-from-a-module-file/2850>\
**Category:** General Usage\
**Created:** [March 24, 2017, 3:09am UTC](https://discourse.julialang.org/t/importing-constant-definition-from-a-module-file/2850 "2017-03-24T03:09:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snir\_Gazit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/snir_gazit/32/11027_2.png) [@Snir\_Gazit](https://discourse.julialang.org/u/Snir_Gazit)\
**Post date:** [March 24, 2017, 3:09am UTC](https://discourse.julialang.org/t/importing-constant-definition-from-a-module-file/2850/1 "2017-03-24T03:09:25Z")

</div>

I would like to create a module file “defs.jl” that contains definitions of several constants such a grid size, dimensionality etc. To do so I have created the following module file:

### defs.jl

module defs  
export D  
const D=2 # dimension  
end

and import it in my code using the command “include(”./defs.jl")".

My problem is that in order to get the value of D I have to type “defs.D” instead of directly D even though D is exported. I tried using “using defs” but that results in an error “Module defs not found in current path.”

Thanks!

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [March 24, 2017, 3:29am UTC](https://discourse.julialang.org/t/importing-constant-definition-from-a-module-file/2850/2 "2017-03-24T03:29:45Z")

</div>

When importing a submodule, and not just a file with code, into your overall module, it is necessary to do it this way (and the capitalization is good practice):

MyDefs.jl

```julia
module MyDefs

export NDIMS

const NDIMS = 2

end # module

```

and in the same directory  
MyModule.jl

```julia
module MyModule

export test

include("MyDefs.jl")

using .MyDefs # note the `.` before the local module name

function test()
    println("NDIMS = $(NDIMS)")
end

end # module

```

then

```julia
using MyModule

test() 
# NDIMS = 2

```
