Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Run python script with args
-
Is it possible to run one Python script from another <b>with a given value for <code>sys.argv</code>?</b> I looked at various functions such as <code>execfile()</code>, but none that I saw supported modification of <code>sys.argv</code>.
-
You could just assign to <code>sys.argv</code> before calling <code>execfile</code>, e.g.:
<pre>import sys
import os
script_name = 'script2.py'
script_path = os.path.join(os.getcwd(), script_name)
prev_argv = sys.argv
sys.argv = [script_path, 'foo', 'bar']
execfile(script_path)
sys.argv = prev_argv</pre> -
Okay I feel stupid now for not trying that lol. Thank you.