# Best way to import module variables to Main scope?

**URL:** <https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 17, 2018, 8:11am UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383 "2018-04-17T08:11:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 17, 2018, 8:11am UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383/1 "2018-04-17T08:11:57Z")

</div>

I run into this problem all the time.

- I want to develop a package where a bunch of pieces are hidden under the hood.
- I like testing along the way in jupyter, so constantly have to use `<Pkg>.blah(blah, blah)`

Writing `<Pkg>` is cumbersome and emotionally taxing.

* * *

Is there a best practices way to safely implement the following code?

// i.e. for a stand-alone package

```julia
using DataStructures

cur_module = DataStructures
all_symbols = get_all_symbols(cur_module)

for cur_symbol in all_symbols
  cur_module.eval(parse("export $cur_symbol"))
end

```

(this could then tie into `Revise.jl` for some more magic…)

* * *

**edit:** an example `get_all_symbols` function can be seen [here](https://github.com/djsegal/Julz.jl/blob/0fce5049177bf4e0723ebe6ac75f66d6affd6f50/src/functions/utils/get_all_symbols.jl)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 17, 2018, 8:35am UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383/2 "2018-04-17T08:35:12Z")

</div>

> [@djsegal](#):
>
> Writing `<Pkg>` is cumbersome and emotionally taxing.

Perhaps an abbreviation?

```julia
import CumbersomeAndEmotionallyTaxingPackageName
const P = CumbersomeAndEmotionallyTaxingPackageName

@test P.blah(blah, blah) == blah

```

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 17, 2018, 8:42am UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383/3 "2018-04-17T08:42:27Z")

</div>

That’s what I’ve been doing.

There still seems like there should be a way to do the described code.

This isn’t supposed to be performant or used in production.

// it’s just supposed to make `Main` into a sandbox for development

* * *

I was asking for suggestions to enhance the above code’s capabilities?

(and make it more idiomatic julia)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 17, 2018, 8:51am UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383/4 "2018-04-17T08:51:16Z")

</div>

The way you would do it in VSCode or Juno is to set the _current module_ that code is evaluate din the same as the one of the package. Both these IDEs make that easy.

For the REPL you can use [https://github.com/tshort/REPLinModule.jl](https://github.com/tshort/REPLinModule.jl).

Not sure how to best do it in IJulia. You can of course use

```julia
@eval <PKG> begin
    ....
end

```

but that might be more annoying than using the prefix everywhere.

You could add some hook into IJulia that changes the hardcoded Main here: [https://github.com/JuliaLang/IJulia.jl/blob/6bbb0693363b9220f5ad6f0ecd8b46c909d95bdf/src/execute\_request.jl#L159](https://github.com/JuliaLang/IJulia.jl/blob/6bbb0693363b9220f5ad6f0ecd8b46c909d95bdf/src/execute_request.jl#L159)

Could be done something like [https://github.com/JuliaLang/IJulia.jl/pull/651](https://github.com/JuliaLang/IJulia.jl/pull/651).

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 17, 2018, 10:11pm UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383/5 "2018-04-17T22:11:13Z")

</div>

With the PR accepted, I think this is resolved?

* * *

**edit:** also, I can’t get `REPLinModule` to plug-and-play as easy as described.

// have you had first experience getting it to work?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 18, 2018, 8:42pm UTC](https://discourse.julialang.org/t/best-way-to-import-module-variables-to-main-scope/10383/6 "2018-04-18T20:42:18Z")

</div>

The new `IJulia` command, `set_current_module`, works like a charm.

* * *

As for running in the REPL, I decided on the following hack:

// couldn’t get `REPLinModule` working ☹

```julia
# ~/.bashrc

alias fus="FUSION=true julia"

```

and

```julia
# ~/.juliarc

if haskey(ENV, "FUSION") && ENV["FUSION"] == "true"
  using FusionSystems

  for cur_symbol in names(FusionSystems, true)
    ( !Base.isidentifier(cur_symbol) ) && continue
    ( in(cur_symbol, (Symbol(FusionSystems), :eval)) ) && continue

    FusionSystems.eval(parse("export $cur_symbol"))
  end
end

```
