title: Global variable not working from module function in ipython
body: <p>I'm sure someone's already answered this, but I can't find it.</p>
  
  <p>I have a script <code>test.py</code> who's sole purpose of existence is to place the variable <code>var</code> into the global namespace:</p>
  
  <pre><code>def test():
      global var
      var = 'stuff'
  </code></pre>
  
  <p>Here's what happens when I run <code>test.py</code> in ipython using <code>%run</code>, then run <code>test()</code>, and then try to access <code>var</code>.</p>
  
  <pre><code>Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
  Type 'copyright', 'credits' or 'license' for more information
  IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
  
  In [1]: %run test.py
  
  In [2]: test()
  
  In [3]: var
  ---------------------------------------------------------------------------
  NameError                                 Traceback (most recent call last)
  &lt;ipython-input-3-84ddba356ca3&gt; in &lt;module&gt;()
  ----&gt; 1 var
  
  NameError: name 'var' is not defined
  
  In [4]:
  </code></pre>
  
  <p>Any idea what's happening? Or how to generally bring it into the local namespace?</p>