# Include file differently when within a module

**URL:** <https://discourse.julialang.org/t/include-file-differently-when-within-a-module/60341>\
**Category:** General Usage\
**Created:** [April 30, 2021, 7:56pm UTC](https://discourse.julialang.org/t/include-file-differently-when-within-a-module/60341 "2021-04-30T19:56:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pg261](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pg261/32/24270_2.png) [@pg261](https://discourse.julialang.org/u/pg261)\
**Post date:** [April 30, 2021, 7:56pm UTC](https://discourse.julialang.org/t/include-file-differently-when-within-a-module/60341/1 "2021-04-30T19:56:04Z")

</div>

Hi !

I want to include a .jl file in two different ways, according as it is included within a module or on its own. I know this sounds confusing ; here is a way to do it, which I think is awkward, and I’m looking for something more elegant.

so i have `foo.jl` with

```julia
macro in_my_module_only(arg)
    if @isdefined SOME_CRAZY_NAME
        return arg
    else
        return nothing
    end
end

@in_my_module_only begin ... end

```

and then “MyModule.jl” goes like this:

```julia
module MyModule
    SOME_CRAZY_NAME= 1
    include("foo.jl")
end

```

This actually works! However, I’m not sure if this is the right way to go about it. I thought of inspecting the current module with `mod= @ __MODULE__ `, but then I’m not sure what to do. If I inspect `string(mod)` I get `Main.MyModule` typically, but in other situations it would be different… or perhaps I should check that `string(@ __MODULE__ )` contains the substring `MyModule` ?

what do you think?

thanks!  
Pierre

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [April 30, 2021, 8:57pm UTC](https://discourse.julialang.org/t/include-file-differently-when-within-a-module/60341/2 "2021-04-30T20:57:04Z")

</div>

The module of the REPL is called “Main”. So you could check against that.
