title: Why is behavior different with respect to global variables in "import module" vs "from module import * "?
body: <p>Let's have <strong>a.py</strong> be:</p>
  
  <pre><code>def foo():
      global spam
      spam = 42
      return 'this'
  </code></pre>
  
  <p>At a console, if I simply <code>import a</code>, things make sense to me:</p>
  
  <pre><code>&gt;&gt;&gt; import a
  &gt;&gt;&gt; a.foo()
  'this'
  &gt;&gt;&gt; a.spam
  42
  </code></pre>
  
  <p>However, if I do the less popular thing and...</p>
  
  <pre><code>&gt;&gt;&gt; from a import *
  &gt;&gt;&gt; foo()
  'this'
  &gt;&gt;&gt; spam
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  NameError: name 'spam' is not defined
  &gt;&gt;&gt; a.spam
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  NameError: name 'a' is not defined
  </code></pre>
  
  <p>I've read opinions about why people don't like "<code>from module import *</code> " from a namespace perspective, but I can't find anything on this behavior, and frankly I figured out that this was the issue I was having by accident.</p>