Does the argparse generate a wrong help message?

jfong at ms4.hinet.net jfong at ms4.hinet.net
Fri Dec 27 22:20:44 EST 2019


The codes in test.py are:
---------
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--foo', nargs='?', help='foo help')
parser.add_argument('--goo', nargs=1, help='goo help')  
args = parser.parse_args()
print(args.foo, args.goo)
---------

But I get the following result:
---------
D:\Works\Python>py test.py -h
usage: test.py [-h] [--foo [FOO]] [--goo GOO]

optional arguments:
  -h, --help   show this help message and exit
  --foo [FOO]  foo help
  --goo GOO    goo help

D:\Works\Python>py test.py --foo 1 --goo 2
1 ['2']
---------

It seems to me that the help message should be:
usage: test.py [-h] [--foo FOO] [--goo [GOO]]

Do I had missed something?

--Jach


More information about the Python-list mailing list