title: How to make global variables work in Spyder inside a function?
body: <p>I cannot modify global variables interactively in Spyder 4.0.0 with Python 3.8, Windows 10.
  There must have been a recent change because this was possible before.</p>
  
  <p>I have the following example file:</p>
  
  <pre><code>x = 5
  def IncreaseX():
      global x
      x += 1
  
  print(x)
  IncreaseX()
  print(x)
  </code></pre>
  
  <ol>
  <li>When I run it (with F5), I get the desired output:</li>
  </ol>
  
  <pre><code>In [1]: runfile('TestGlobals.py', wdir='D:')
  5
  6
  </code></pre>
  
  <ol start="2">
  <li>However, if I try to run the IncreaseX() function from the embedded Ipython console, it does not change the value of the global variable:</li>
  </ol>
  
  <pre><code>In [2]: x
  Out[2]: 6
  
  In [3]: IncreaseX()
  
  In [4]: x
  Out[4]: 6
  </code></pre>
  
  <ol start="3">
  <li>The same occurs if I select the last 3 rows of my example, and I run them (with F9):</li>
  </ol>
  
  <pre><code>In [5]: print(x)
     ...: IncreaseX()
     ...: print(x)
  6
  6
  </code></pre>
  
  <ol start="4">
  <li>The behaviour is different if I select all the rows of my example file and run them (with F9):</li>
  </ol>
  
  <pre><code>In [6]: x = 5
     ...: def IncreaseX():
     ...:     global x
     ...:     x += 1
     ...: 
     ...: print(x)
     ...: IncreaseX()
     ...: print(x)
  5
  6
  </code></pre>
  
  <ol start="5">
  <li>After I do this, I can modify the value of the global variable.
  Repeating the exact same code of step 2., I obtain the desired outcome:</li>
  </ol>
  
  <pre><code>In [7]: x
  Out[7]: 6
  
  In [8]: IncreaseX()
  
  In [9]: x
  Out[9]: 7
  </code></pre>
  
  <p>Does anyone understand this behaviour? How can I restore the old behaviour (i.e., having step 2. to work directly as step 5.)?</p>
  
  <p>I know that it is generally very bad to use global variables.
  However, I need to interactively modify some variables while I am controlling an experiment, hence a few correctly working global variables strongly simplify my workflow.</p>
  
  <hr>
  
  <p><strong>FOUND IT!!</strong></p>
  
  <p>Spyder/Preferences/Run/General settings/Run in console's namespace instead of an empty one</p>
  
  <p>With this option turned on, the old behaviour of globals is restored.</p>