paul j3 added the comment:
Here's a possible solution to the problem (assuming there really is one):
- redefine REMAINDER so it matches a '((?:A[AO]*)?)' pattern (where O is a
string that looks like an optional flag, A an argument string). I've added the
condition that the first match (if
paul j3 added the comment:
An alternative to Jason's example:
parser = argparse.ArgumentParser()
parser.add_argument('app')
parser.add_argument('--config')
parser.add_argument('app_args', nargs=argparse.REMAINDER)
args = parser.parse_args(['--config', 'bar', 'app'])
print vars(args)
# as
paul j3 added the comment:
By the way, parser.parse_args() uses parse_known_arg(). parse_known_args
returns a Namespace and a list of unknown arguments. If that list is empty,
parse_args returns the Namespace. If the list is not empty, parse_args raises
an error.
So parse_known_args does
Chris Jerdonek added the comment:
See also issue 17050 for a reduced/simple case where argparse.REMAINDER doesn't
work (the case of the first argument being argparse.REMAINDER).
--
nosy: +chris.jerdonek
___
Python tracker rep...@bugs.python.org
Michael Edwards added the comment:
I'm attaching my own bug repro script for Eric. Is this sufficient? I can
demonstrate the entire resulting Namespace, but the problem is that argparse
doesn't even produce a Namespace. The cases I show simply fail.
--
nosy: +Michael.Edwards
Added
Jason R. Coombs added the comment:
I also ran into this problem. I put together this script to reproduce the issue:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('app')
parser.add_argument('--config')
parser.add_argument('app_args', nargs=argparse.REMAINDER)
args =
Idan Kamara added the comment:
Unfortunately parse_known_args is buggy too: http://bugs.python.org/issue16142
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
Idan Kamara added the comment:
I just ran into this issue myself and worked around it by using
parse_known_args*.
* http://docs.python.org/library/argparse.html#partial-parsing
--
nosy: +idank
___
Python tracker rep...@bugs.python.org
Éric Araujo mer...@netwok.org added the comment:
Thanks for the report. Could you edit your script to add the expected results,
for example Namespace(foo=..., command=[...])?
--
nosy: +eric.araujo
stage: - needs patch
versions: +Python 3.3
___
New submission from Arnout van Meer rr2...@gmail.com:
Reproduction case is attached and should speak for itself, but the short brief
is that the argparse.REMAINDER behaviour is very inconsistent based on what
(potentially) defined argument handlers come before it.
Tested this on Python 2.7 on
Changes by Arnout van Meer rr2...@gmail.com:
Removed file: http://bugs.python.org/file24704/worker.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
Changes by Arnout van Meer rr2...@gmail.com:
Added file: http://bugs.python.org/file24704/worker.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
Changes by Arnout van Meer rr2...@gmail.com:
Added file: http://bugs.python.org/file24705/bug_argparse.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
Changes by Arnout van Meer rr2...@gmail.com:
Removed file: http://bugs.python.org/file24704/worker.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
Changes by Arnout van Meer rr2...@gmail.com:
Removed file: http://bugs.python.org/file24704/worker.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
Changes by Arnout van Meer rr2...@gmail.com:
Added file: http://bugs.python.org/file24704/worker.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14174
___
16 matches
Mail list logo