I have a program that is run from the command line like this
python program.py 100 rfile
How can I write a new script so that instead of running it with just the '100' argument, I can run it consecutively with a list of arguments like [50, 100, 150, 200]?
Edit: The reason I am asking is that I want to record how 'program.py' executes with different arguments.
If you create a bash file like this
#!/bin/bash
for i in 1 2 3 4 5
do
python program.py $i rfile
done
then do chmod +x
on that file, when you run it, it will run these consecutively:
python program.py 1 rfile
python program.py 2 rfile
python program.py 3 rfile
python program.py 4 rfile
python program.py 5 rfile
You can use Devrim's shell approach or you can modify your script:
If your original script worked like this:
import sys
do_something(sys.argv[1], sys.argv[2])
You could accomplish what you want like this:
def main(args):
for arg in args[:-1]:
do_something(arg, args[-1])
if __name__ == '__main__':
import sys
main(sys.argv[1:])
You would invoke it like so:
python program.py 50 100 150 200 rfile
I'm guessing at what you want. Please clarify if this isn't right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With