title: Execution of Python code with -m option or not
body: <p>The python interpreter has <code>-m</code> <em>module</em> option that "Runs library module <em>module</em> as a script". </p>
  
  <p>With this python code a.py:</p>
  
  <pre><code>if __name__ == "__main__":
      print __package__
      print __name__
  </code></pre>
  
  <p>I tested <code>python -m a</code> to get</p>
  
  <pre><code>"" &lt;-- Empty String
  __main__
  </code></pre>
  
  <p>whereas <code>python a.py</code> returns</p>
  
  <pre><code>None &lt;-- None
  __main__
  </code></pre>
  
  <p>To me, those two invocation seems to be the same except __package__ is not None when invoked with -m option. </p>
  
  <p>Interestingly, with <code>python -m runpy a</code>, I get the same as <code>python -m a</code> with python module compiled to get a.pyc. </p>
  
  <p>What's the (practical) difference between these invocations? Any pros and cons between them? </p>
  
  <p>Also, David Beazley's Python Essential Reference explains it as "<em>The -m option runs a library module as a script which executes inside the __main__ module prior to the execution of the main script</em>". What does it mean?</p>