[issue18943] argparse: default args in mutually exclusive groups
Vincas Dargis <vin...@gmail.com> added the comment: On 2017-12-06 20:28, paul j3 wrote: > The default value is used *if the flag is not provided at all.* > > "nargs='?'" provides a third option, assigning the 'const' value *if the flag > is used without an argument*. This did a "click" in my head. It works now with `nargs='?'` and `const='MediaProfile000'` as expected, thanks! I am really sorry for the noise, due to misunderstanding while reading (skipping-throuhg?) Python documentation. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue18943> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18943] argparse: default args in mutually exclusive groups
Vincas Dargis <vin...@gmail.com> added the comment: On 2017-12-06 19:43, paul j3 wrote: > With one flag but not its argument, I get the error that you display. That > has nothing to do with the grouping. > > 0932:~/mypy/argdev$ python3 issue18943.py --ptz-get-status > usage: issue18943.py [-h] > (--device-get-capabilities | --ptz-absolute-move x y z > | --ptz-get-status MEDIA_PROFILE) > issue18943.py: error: argument --ptz-get-status: expected one argument In my example I pasted, I had hardcoded arguments: ``` pprint.pprint(parser.parse_args(['--ptz-get-status'])) `` I expected `python myscript.py --ptz-get-status` to work, because default value is set. I do not compute that "With one flag but not its argument", sorry. It has default argument set, shoudn't that work? Thanks! -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue18943> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18943] argparse: default args in mutually exclusive groups
Vincas Dargis <vin...@gmail.com> added the comment: Any progress with this? I believe it would fix my use case: ``` import argparse import pprint parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--device-get-capabilities', action='store_true', help='Execute GetCapabilities action from ONVIF devicemgmt.wsdl') group.add_argument('--ptz-absolute-move', nargs=3, metavar=('x', 'y', 'z'), help='Execute AbsoluteMove action from ONVIF ptz.wsdl') group.add_argument('--ptz-get-status', metavar='MEDIA_PROFILE', default='MediaProfile000', help='Execute GetSatus action from ONVIF ptz.wsdl for a media profile (default=%(default)s)') pprint.pprint(parser.parse_args(['--ptz-get-status'])) ``` Outputs (using 3.6.3): ``` python3 ./test-ex-group-with-defult.py usage: test-ex-group-with-defult.py [-h] (--device-get-capabilities | --ptz-absolute-move x y z | --ptz-get-status MEDIA_PROFILE) test-ex-group-with-defult.py: error: argument --ptz-get-status: expected one argument ``` Are there know workarounds for this? -- nosy: +talkless ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue18943> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com