title: What is a module variable vs. a global variable?
body: <p>From <a href="https://stackoverflow.com/q/40941211/774575">a comment</a>: "<em>global</em> in Python basically means at the module-level". However running this code in a file named <code>my_module.py</code>:</p>
  
  <pre><code>import my_module as m
  
  foo = 1
  m.bar = m.foo + 1
  
  if __name__ == "__main__":
      print('foo:', foo)
      print('m.foo:', m.foo)
      print('m.bar:', m.bar, '\n')
  
      for attrib in ('foo', 'bar'):
          print("'{0}' in m.__dict__: {1}, '{0}' in globals(): {2}".format(
              attrib,
              attrib in m.__dict__,
              attrib in globals()))
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>foo: 1
  m.foo: 1
  m.bar: 2 
  
  'foo' in m.__dict__: True, 'foo' in globals(): True
  'bar' in m.__dict__: True, 'bar' in globals(): False
  </code></pre>
  
  <p>What exactly are the module and global namespaces?</p>
  
  <p>Why is there a <code>__dict__</code> attribute in module namespace but not in global namespace?</p>
  
  <p>Why is <code>m.bar</code> part of <code>__dict__</code> and not part of <code>globals()</code>?</p>