1

list = ['12345','23456']

I have a script "test.py",I need to pass the values in a given list above as parameters to this script with "pick" as option, can anyone provide input on how this can be done?

Final goal is to run the script like the following:

 test.py pick 12345 23445
Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94
user2341103
  • 2,333
  • 5
  • 20
  • 19

3 Answers3

0

You should parse the arguments with sys.argv

http://docs.python.org/2/library/sys.html#sys.argv

If you want to run the script from another script you can use os.system

os.system("script2.py 1")
nacholibre
  • 3,874
  • 3
  • 32
  • 35
0

Aside from using sys.argv, you can use getopt.

Mr_Spock
  • 3,815
  • 6
  • 25
  • 33
0

Use subprocess

import subprocess

lst = ['12345','23456']
cmd = ['test.py', 'pick']
cmd.extend(lst)
subprocess.call(cmd)

Try this code. This will invoke the script test.py with args pick 12345 23456

Muhammed K K
  • 1,100
  • 2
  • 8
  • 19