0

I'm new to Python. The file "main.py" must call the file "add.py". I want to invoke the interpreter as

python main.py add John Doe Some Possible Names

That is variable length for sys.argv. I want from within main.py to call for add.py and pass it all the arguments except add and main.py. How can I do this?

Andrew
  • 41
  • 1
  • 5
  • possible duplicate question https://stackoverflow.com/questions/3781851/run-a-python-script-from-another-python-script-passing-in-args – devesh Sep 02 '18 at 18:51

1 Answers1

1

I don't know why you pass in add rather than add.py, but nevertheless, you can use subprocess.call:

import sys, subprocess
subprocess.call([sys.executable, sys.argv[1] + '.py'] + sys.argv[2:])
Joe Iddon
  • 20,101
  • 7
  • 33
  • 54