classification
Title: argparse usage line is wrong
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse optionals with nargs='?', '*' or '+' can't be followed by positionals
View: 9338
Assigned To: Nosy List: anton.barkovsky, chris.jerdonek, slikts
Priority: normal Keywords:

Created on 2012-07-23 09:48 by slikts, last changed 2012-07-23 16:46 by bethard. This issue is now closed.

Messages (1)
msg166217 - (view) Author: Reinis Ivanovs (slikts) Date: 2012-07-23 09:48
I set a positional argument and an optional argument that accepts a list:

> parser = argparse.ArgumentParser()
> parser.add_argument('foo')
> parser.add_argument('-bar', nargs='*')

The usage line I get from --help is this:

> $ example.py --help
> usage: example.py [-h] [-bar [BAR [BAR ...]]] foo

Trying to actually follow the usage instructions produces this error:

> $ example.py -bar x y z
> error: too few arguments

Reversing the argument order works however:

> $ example.py z -bar x y

So the usage instructions are clearly wrong.
History
Date User Action Args
2012-07-23 16:46:08bethardsetstatus: open -> closed
2012-07-23 16:46:01bethardsetsuperseder: argparse optionals with nargs='?', '*' or '+' can't be followed by positionals
resolution: duplicate
2012-07-23 15:27:14chris.jerdoneksetnosy: + chris.jerdonek
2012-07-23 14:47:09anton.barkovskysetnosy: + anton.barkovsky
2012-07-23 09:48:37sliktscreate