# Is it possible to know if module is imported from another one?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-know-if-module-is-imported-from-another-one/37224>\
**Category:** General Usage\
**Created:** [April 8, 2020, 8:54am UTC](https://discourse.julialang.org/t/is-it-possible-to-know-if-module-is-imported-from-another-one/37224 "2020-04-08T08:54:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abulak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abulak/32/28314_2.png) [@abulak](https://discourse.julialang.org/u/abulak)\
**Post date:** [April 8, 2020, 8:54am UTC](https://discourse.julialang.org/t/is-it-possible-to-know-if-module-is-imported-from-another-one/37224/1 "2020-04-08T08:54:56Z")

</div>

As in the topic, I’d like to execute some code (e.g. in `__init_`) based on the information that my module has not been `used`/`imported` into `Main`. I tried `parentmodule` and `Base.moduleroot` etc. but since `Main` is no longer special in julia, each module is it’s own root…

MWE (works only if module is defined in `Main`):

```julia
julia> module InnerModule
           function __init__ ()
               parent_mod = parentmodule(@ __MODULE__ )
               @info "imported from $(last(fullname(parent_mod)))"
           end
       end
[ Info: imported from Main
Main.InnerModule

julia> module OuterModule
           module InnerModule
                  function __init__ ()
                      parent_mod = parentmodule(@ __MODULE__ )
                      @info "imported from $(last(fullname(parent_mod)))"
                  end
          end
          import .InnerModule
       end
[ Info: imported from OuterModule
Main.OuterModule

```
