Run python from python without Popen or os.system
<p>I have a wrapper python script which repeatedly calls another python script via <code>os.system</code>. This works well enough, but there is quite a performance hit invoking the sub-shell and importing the modules again and again. How might I transform this to something more elegant and performant?</p>

<pre><code>counter = 0
for thing in list_of_stuff:
    os.system("python inner_script.py %s result_%s" % (thing, counter)
    counter += 1
</code></pre>

<p>I would prefer to do this all in the wrapper, but can modify <em>inner-script.py</em> if that's the only or best way. </p>

<p>If it's relevant, the environment is Python 2.7 on Windows.  </p>

<p><strong>edit:</strong> I don't just import inner_script because it doesn't understand the command line parameters:</p>

<pre><code>import inner_script    
counter = 0
for thing in ['TR2','TR5']:
    inner_script('%s result_%s' % (thing, counter))
counter += 1
</code></pre>

<p>result:</p>

<pre><code>C:\&gt; python xx-wrapper.py

inner_script [input features] [output workspace]
</code></pre>

<p>which is the usage message returned by inner_script.py:</p>

<pre><code>if len(sys.argv) &lt; 3:
    print usage
    exit()

in_features = sys.argv[1]
out_folder  = sys.argv[2]

main(in_features, out_folder)
</code></pre>
