# Usage of parentmodule()

**URL:** <https://discourse.julialang.org/t/usage-of-parentmodule/21625>\
**Category:** General Usage\
**Created:** [March 8, 2019, 8:46am UTC](https://discourse.julialang.org/t/usage-of-parentmodule/21625 "2019-03-08T08:46:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreHat](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@AndreHat](https://discourse.julialang.org/u/AndreHat)\
**Post date:** [March 8, 2019, 8:46am UTC](https://discourse.julialang.org/t/usage-of-parentmodule/21625/1 "2019-03-08T08:46:04Z")

</div>

I’m having some trouble with the new parentmodule() function in Julia 1.0. According to the Julia 0.7.0 release notes module\_parent() is depreciated in favor of parentmodule(), however parentmodule() in Julia 1.0 returns differently than module\_parent() did in Julia 0.6.  
Some example code:

```julia
#julia 1.0
module ModA
   global __parent = nothing
   function __init__ ()
      global __parent = parentmodule(ModA)
   end
end

using ModA
ModA.__parent

This returns ModA.__parent = ModA

#julia 0.6
module ModA
   global __parent = nothing
   function __init__ ()
      global __parent = module_parent(ModA)
   end
end

using ModA
ModA.__parent

```

This returns ModA.\_\_parent = Main

Is this how moduleparent() is supposed to work? If so, how do I get the same functionality as the Julia 0.6 code?

---

<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 8, 2019, 9:12am UTC](https://discourse.julialang.org/t/usage-of-parentmodule/21625/2 "2019-03-08T09:12:56Z")

</div>

name the initialization function ` __init__ ` not `init`, then it works as you expect

```julia
module Module
    the_parent = nothing # no need to declare this global
    function __init__ ()
        global the_parent = parentmodule(Module)
    end
end

julia> using .Module # notice the `.` (Module is defined in the REPL)

julia> Module.the_parent
Main

```

---

<div class="post-metadata">

**Author:** ![AndreHat](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@AndreHat](https://discourse.julialang.org/u/AndreHat)\
**Post date:** [March 8, 2019, 2:27pm UTC](https://discourse.julialang.org/t/usage-of-parentmodule/21625/3 "2019-03-08T14:27:01Z")

</div>

Hi Jeffrey  
Thank you for the reply, I edited my original post to put the code in a code block, sorry, I missed that. The problem comes in when you call the module from the load path like so:

```julia
push!(LOAD_PATH, "path to module")

using ModA
ModA.__parent

```

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [March 12, 2019, 2:29am UTC](https://discourse.julialang.org/t/usage-of-parentmodule/21625/4 "2019-03-12T02:29:56Z")

</div>

In an effort to make `Main` less special in v1.0, many modules now are their own parent, instead of requiring them all to live in the `Main` namespace.

---

<div class="post-metadata">

**Author:** ![AndreHat](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@AndreHat](https://discourse.julialang.org/u/AndreHat)\
**Post date:** [March 12, 2019, 2:37pm UTC](https://discourse.julialang.org/t/usage-of-parentmodule/21625/5 "2019-03-12T14:37:02Z")

</div>

Hi Jameson.  
Thank you for the reply, so the code work as intended and the module parent actually changed, that’s good to know.
