Executing External Python Scripts with Arguments from Within Another Script
The goal of this discussion is to execute a Python script (script2.py) from within another Python script (script1.py) while passing arguments to script2.py as if they were being inputted from the command line.
One method to accomplish this is by using os.system in script1.py:
<code class="python">os.system("script2.py 1")</code>
This command will execute script2.py with the argument "1" as its first argument.
It's important to note that using execfile to achieve this goal is not recommended because it executes the statements of script2.py within the same execution context as script1.py, resulting in no change in sys.argv in script2.py.
The above is the detailed content of How Can I Execute an External Python Script with Arguments from Another Script?. For more information, please follow other related articles on the PHP Chinese website!