How to execute file in Python with arguments using import?
<p>I read that you can execute a file using <code>import</code> like this<br>
<strong>file.py</strong>:</p>

<pre><code>#!/usr/bin/env python
import file2
</code></pre>

<p><strong>file2.py</strong>:</p>

<pre><code>#!/usr/bin/env python
print "Hello World!"
</code></pre>

<p>And <strong>file.py</strong> will print <code>Hello World</code>. How would I execute this file with arguments, using <code>import</code>?</p>

<p>Program arguments are available in <code>sys.argv</code> and can be used by any module. You could change file2.py to</p>

<pre><code>import sys
print "Here are my arguments", sys.argv
</code></pre>

<p>You can use the <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow">argparse</a> module for more complex parsing.</p>

python python-2.7 python-import