Message128071
| Author |
andersk |
| Recipients |
andersk, bethard, drm, eric.araujo, eric.smith, gdb, nelhage, r.david.murray |
| Date |
2011年02月06日.19:12:18 |
| SpamBayes Score |
0.0048026484 |
| Marked as misclassified |
No |
| Message-id |
<1297019538.75.0.803498628689.issue9334@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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) |
|