[issue9571] argparse: Allow the use of -- to break out of nargs and into subparser

Michael.Elsdörfer report at bugs.python.org
Wed Aug 11 21:21:27 CEST 2010


New submission from Michael.Elsdörfer <michael at elsdoerfer.info>:

argparse already seems to support -- to indicate that what follows are positional arguments. However, I would like to parse something like:

./script.py --ignore one two -- COMMAND

I.e., --ignore is an nargs='+' argument, and I need a way to break out of --ignore and have argparse consider what follows on it's own merits. If COMMAND in the above example refers to a subparser, this won't work:

error: invalid choice: '--' (choose from 'command1', 'command2', 'command3')

I'm not sure what's the best solution here. Allowing -- here would change the semantics of forcing everything that follows to be positional arguments, since the subparser might have flags. I'm not sure if that is what is required by Unix conventions, but if not, then I think it makes sense to allow -- to be followed by a subparser.

----------
components: Library (Lib)
messages: 113616
nosy: elsdoerfer
priority: normal
severity: normal
status: open
title: argparse: Allow the use of -- to break out of nargs and into subparser
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3

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


More information about the Python-bugs-list mailing list