title: Why is Python running my module when I import it, and how do I stop it?
body: <p>I have a Python program I'm building that can be run in either of 2 ways: the first is to call "python main.py" which prompts the user for input in a friendly manner and then runs the user input through the program.  The other way is to call "python batch.py <em>-file-</em>" which will pass over all the friendly input gathering and run an entire file's worth of input through the program in a single go.</p>
  
  <p>The problem is that when I run "batch.py" it imports some variables/methods/etc from "main.py", and when it runs this code:</p>
  
  <pre><code>import main
  </code></pre>
  
  <p>at the first line of the program, it immediately errors because it tries to run the code in "main.py".</p>
  
  <p>How can I stop Python from running the code contained in the "main" module which I'm importing?</p>