Home > Net >  Passing range of numbers from terminal to Python script
Passing range of numbers from terminal to Python script

Time:01-19

I have a python script which is executed from terminal as

script.py 0001

where 0001 indicates the subcase to be run. If I have to run different subcases, then I use

script.py 0001 0002

Question is how to specify a range as input? Lets say I want to run 0001..0008. I got to know seq -w 0001 0008 outputs what I desire. How to pipe this to Python as input from terminal? Or is there a different way to get this done?

CodePudding user response:

Tried the following already but did not work earlier as I did not have the subcases pulled in the script repo. The following works:

script.py 000{1..8}

CodePudding user response:

import sys
r = sys.argv[1].split("..")
for x in range(r[0], r[1] 1):
    # ... does this do what you want ?
  • Related