title: Run a Python script from another Python script, passing in arguments
body: <p>I want to run a Python script from another Python script. I want to pass variables like I would using the command line.</p>
  
  <p>For example, I would run my first script that would iterate through a list of values (0,1,2,3) and pass those to the 2nd script <code>script2.py 0</code> then <code>script2.py 1</code>, etc.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/1186789/what-is-the-best-way-to-call-a-python-script-from-another-python-script">Stack&nbsp;Overflow question 1186789</a> which is a similar question, but ars's answer calls a function, where as I want to run the whole script, not just a function, and balpha's answer calls the script but with no arguments. I changed this to something like the below as a test:</p>
  
  <pre><code>execfile("script2.py 1")
  </code></pre>
  
  <p>But it is not accepting variables properly. When I print out the <code>sys.argv</code> in script2.py it is the original command call to first script "['C:\script1.py'].</p>
  
  <p>I don't really want to change the original script (i.e. script2.py in my example) since I don't own it.</p>
  
  <p>I figure there must be a way to do this; I am just confused how you do it.</p>