[issue9334] argparse does not accept options taking arguments beginning with dash (regression from optparse)

Anders Kaseorg report at bugs.python.org
Sun Feb 6 20:12:18 CET 2011


Anders Kaseorg <andersk at mit.edu> added the comment:

There are some problems that ‘=’ can’t solve, such as options with nargs ≥ 2.  optparse has no trouble with this:

>>> parser = optparse.OptionParser()
>>> parser.add_option('-a', nargs=2)
>>> parser.parse_args(['-a', '-first', '-second'])
(<Values at 0x7fc97a93a7e8: {'a': ('-first', '-second')}>, [])

But inputting those arguments is _not possible_ with argparse.

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-a', nargs=2)
>>> parser.parse_args(['-a', '-first', '-second'])
usage: [-h] [-a A A]
: error: argument -a: expected 2 argument(s)

----------

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


More information about the Python-bugs-list mailing list