parsing - Python argparse key=value parameters -
i've tried answer on stack overflow, can't find exact answer particular case.
this first link has same question in first section, unanswered (python argparse: parameter=value). , second question similar, can't seem working particular case ( using argparse parse arguments of form "arg= val").
so situation -- re-writing python wrapper used many other scripts (i prefer not modify these other scripts). currently, python wrapper called command line arguments of form --key=value number of different arguments, parsed manually. parse them argparse.
n.b. argument names unwieldy, renaming using dest option in add_argument.
parser = argparse.argumentparser(description='wrappin ronnie reagan') parser.add_argument("--verylongargname1", nargs=1, dest="arg1", required=true) parser.add_argument("--verylongargname2", nargs=1, dest="arg2") parser.add_argument("--verylongargname3", nargs=1, dest="arg3") useropts = vars(parser.parse_args()) which, while apparently parsing passed command lines correctly, displays help:
usage: testing_argsparse.py [-h] --verylongargname1 arg1 [--verylongargname2 arg2] [--verylongargname3 arg3] testing_argsparse.py: error: argument --verylongargname1 required but want parameters specified --key=value format, not --key value. i.e.
usage: testing_argsparse.py [-h] --verylongargname1=arg1 [--verylongargname2=arg2] [--verylongargname3=arg3] testing_argsparse.py: error: argument --verylongargname1 required thanks in advance!
testing_argsparse.py --verylongargname1=foo works. argparse module accepts both --verylongargname1=foo , --verylongargname1 foo formats.
what exact command line arguments trying pass argparse that's causing not work?
Comments
Post a Comment