[issue9338] argparse optionals with nargs='?', '*' or '+' can't be followed by positionals

Paul Hawkins report at bugs.python.org
Tue Oct 22 03:51:34 CEST 2013


Paul Hawkins added the comment:

I ran into this bug the first time I needed nargs + in a tool.  

I found of course that if the option with the nargs is followed by another option before the positional arguments it will work as expected.  But then the help would have to point this out, and it still could be used incorrectly (so then I get a mail about a bug in my tool.) ;-)>

My workaround was to use action=append instead of nargs, then user would just have to give the option for each nargs desired.  Since my use would be short this was OK.  But the usage message does not reflect the multiple use nature of this option

But what I expected to find in the doc was a way to specify the use of a separator char between the nargs option arguments.  For example specify that ',' is the separator arg (currently a space is the separator.)  So if option is -foo the cli could be:

myprog.py -foo bar1,bar2,bar3 pos1 pos2

(Of course I could just have the tool take a comma delimited single argument and parse it in the tool's logic, but again then a custom usage message would be needed.)

Has this solution been considered?

----------
nosy: +phawkins

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9338>
_______________________________________


More information about the Python-bugs-list mailing list