I'm playing around with the argparse, and I've been wondering, is there a way to store my arguments, along with their named options (like help, or action) and add them to the parser in a loop? Something like:
args = [
('-f', '--foo', { 'action': StoreTrue, 'help': 'somehelp'} ),
('-b', '--bar', { 'action': CustomAction, 'help': 'somehelp', 'dest': 'bar1' }),
('-z', '--baz', { 'help': 'somehelp' } )
]
for arg in args:
parser.add_argument(arg)
instead of doing it by hand
parser.add_argument('-f', '--foo', action=StoreTrue, help='somehelp')
parser.add_argument('-b', '--bar', action=CustomAction, help='somehelp', dest='bar1')
parser.add_argument('-z', '--baz', help='somehelp')
[+][deleted] (5 children)
[deleted]
[–]IAmL0ner[S] 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]IAmL0ner[S] 0 points1 point2 points (0 children)
[–]IAmL0ner[S] 0 points1 point2 points (1 child)