0
import argparse

parser = argparse.ArgumentParser()

parser.add_argument("-v", "--verbosity", action="store_true",
                    help="Pass the first input parameter with either -f or -d 
     and the second parameter should be the path of the output file")
parser.add_argument("-o", "--output",help="please give the path of the file")
parser.add_argument("-of", "--format",help="provide the output format")

args = parser.parse_args()

when I issue help on the program like:python arg_parse.py -h,Im getting the following help

python arg_parse.py -h

usage: arg_parse.py [-h] [-v] [-o OUTPUT] [-of FORMAT]


optional arguments:

  -h, --help            show this help message and exit

  -v, --verbosity       Pass the first input parameter with either -f or -d
                        and the second parameter should be the path of the
                        output file

  -o OUTPUT, --output OUTPUT
                        please give the path of the file

  -of FORMAT, --format FORMAT
                        provide the output format

so if we observe optional arguments in the help message for verbosity and help look same as below:

-h, --help    

-v, --verbosity 

But for OUTPUT and FORMAT we are getting multiple options which are having redundancy as below:

-o OUTPUT, --output OUTPUT

-of FORMAT, --format FORMAT

so the only difference is I put action parameter in verbosity. Now I need the same options for OUTPUT and FORMAT without action parameter.Please help on this.

hpaulj
  • 221,503
  • 14
  • 230
  • 353
Chinna
  • 79
  • 7
  • The intention is show your users which options just need the flag, and which need an argument (the stated or implied `nargs`). Yes, that is also marked in the `usage`. Most people aren't bothered by the redundancy. You can modify the display with the `metavar` parameter, even setting it to `metavar=''` (though there is still an extra space). – hpaulj Jun 04 '18 at 06:13
  • Related: https://stackoverflow.com/questions/23936145/python-argparse-help-message-disable-metavar-for-short-options,https://stackoverflow.com/questions/30704631/changing-the-metavar-value-in-argparse-only-in-argument-listing-and-not-in-its-u,https://stackoverflow.com/questions/40497140/arparse-output-not-aligned, https://stackoverflow.com/questions/18275023/dont-show-long-options-twice-in-print-help-from-argparse – hpaulj Jun 04 '18 at 06:21

0 Answers0