I need to have a command line in the form
python script.py --step1=100 --step3=53 --step2=34
The requirements are
- I don't know how many
--stepN
flags there are in advance - The order of the
--stepN
flags are not set, so I cannot just useaction='append'
I'm also interested in these restrictions too:
- The step numbers should be continuous, so if
--step20
is used but--step19
is missing, this is an error. - I want the destination of the values in one list. So in the above command line example, I want to do something like
args = parser.parse_args()
args.steps # is list [100, 34, 53]
Can argparse
take a pattern of agruments, and somehow I can write a custom action or type to do what I want? I'm thinking something like
parser.add_argument('--step*',
type=CustomType,
action=CustomAction,
help='Use --step1=a --step2=b, ....')