1

I'm using the choices argument in argparse. If I run -h I get the choices two times, once for -a and once for --argument. As I have around 30 options with long names the help text is quite cluttered. Can I only get it once? (without removing one of the flags). Output from help:

$ python3 test.py  -h
usage: test.py [-h] [-a {Option1,Option2}]

optional arguments:
   -h, --help            show this help message and exit
   -a {Option1,Option2}, --argument {Option1,Option2}
                    Help.

Minimal example:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--argument', help='Help.', choices=['Option1', 'Option2'])

args = parser.parse_args()
ErikXIII
  • 557
  • 2
  • 12
  • 1
    Experiment with the `metavar` parameter. – hpaulj Oct 07 '20 at 14:43
  • 1
    You could also omit the `--argument`, and optionally set `dest='argument'`. `help` is set up to show your users all the ways they could provide the values. A long list of `choices` is problem for any machine generated help. – hpaulj Oct 07 '20 at 15:25

0 Answers0