On Sat, Dec 28, 2019 at 2:26 PM <jf...@ms4.hinet.net> wrote:
>
> 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?
>

Can you elaborate on why you expect this? You've declared one of them
to have a single mandatory argument, and the other a single optional
argument. This corresponds to what I'm seeing.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to