parameters - Python: don't display 'choices' with argparse -


with argparse, have following line:

parser.add_argument("-p", "--parameter", type=str, default=none, nargs='+',                         help="some option",                         choices=allvalues.keys()                         ) 

the resulting help message shows values in allvalues:

-p {a ,b ,c , d, e, f, g, h, i, l, m; ,b ,c , d, e, f, g, h, i, l, m} [{a ,b ,c , d, e, f, g, h, i, l, m} ...], --parameter {a ,b ,c , d, e, f, g, h, i, l, m; ,b ,c , d, e, f, g, h, i, l, m} [{a ,b ,c , d, e, f, g, h, i, l, m; ,b ,c , d, e, f, g, h, i, l, m} ...] option

can remove {a ,b ,c , d, e, f, g, h, i, l, m; ,b ,c , d, e, f, g, h, i, l, m} above , just display name of parameter , help message?

use metavar argument::

parser.add_argument("-p", "--parameter", type=str, default=none, nargs='+',                     help="some option",                     choices=allvalues.keys(),                     metavar='parameter'                     ) 

this give::

-p parameter, --parameter parameter option 

if don't want show metavariable @ consider passing '' metavar. otherwise, believe have create own custom formatter classes , pass argumentparser.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -