# Not Sharing variables between Jupyter Notebook nbincludes

**URL:** https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598
**Category:** General Usage
**Created:** [August 17, 2018, 2:30am UTC](https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598 "2018-08-17T02:30:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [August 17, 2018, 2:30am UTC](https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598/1 "2018-08-17T02:30:20Z")

</div>

I have a set of jupyter notebooks that I would like to execute in a test so as to ensure that they all run:

```julia
for file in readdir(NOTEBOOK_DIR)
    if splitext(file)[2] == ".ipynb"
        println("Running ", file)
        nbinclude(joinpath(NOTEBOOK_DIR, file))
    end
end

```

Unfortunately, imported notebooks will be affected by the code imported by notebooks before them. In Julia 0.7 or 1.0 is it still possible to clear the workspace? Is there an alternative trick I can use?

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [August 17, 2018, 6:28am UTC](https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598/2 "2018-08-17T06:28:48Z")

</div>

Include them in separate modules.

---

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [August 17, 2018, 2:47pm UTC](https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598/3 "2018-08-17T14:47:32Z")

</div>

Thanks fredrikekre, could you please elaborate. Including them as separate modules makes me think my code would be:

```julia
module A
    nbinclude("notebookA.ipynb")
end
module B
    nbinclude("notebookB.ipynb")
end
module C
    nbinclude("notebookC.ipynb")
end

```

While that may work, it isn’t amenable to automatically testing any notebook I put in the directory.

---

<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: [August 17, 2018, 3:15pm UTC](https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598/4 "2018-08-17T15:15:01Z")

</div>

```julia
for x in mynotebooks
    m = Module()
    @eval m begin
        using NBInclude
        nbinclude($x)
    end
end

```

perhaps?

---

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [August 19, 2018, 12:46am UTC](https://discourse.julialang.org/t/not-sharing-variables-between-jupyter-notebook-nbincludes/13598/5 "2018-08-19T00:46:56Z")

</div>

Even works in Julia 0.6. Thanks!
