[issue11354] argparse: nargs could accept range of options count
Christoph Anton Mitterer
report at bugs.python.org
Thu Jul 9 20:20:24 EDT 2020
Christoph Anton Mitterer <calestyo at scientia.org> added the comment:
Next to code readability, there's IMO one could reason to properly support this would be a clean and easy way to get proper help strings for such options.
Of course I can do something like:
parser = argparse.ArgumentParser()
parser.add_argument("--foo", nargs="+", help="Mae govannen", metavar=("bar", "baz"))
args = parser.parse_args()
and later check that, say, only 2 arguments are allowed.
But the help text will be an ugly:
>$ python3 f.py --help
>usage: f.py [-h] [--foo bar [baz ...]]
>
>optional arguments:
> -h, --help show this help message and exit
> --foo bar [baz ...] Mae govannen
indicating that >1 options were allowed.
----------
nosy: +calestyo
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue11354>
_______________________________________
More information about the Python-bugs-list
mailing list