[issue34744] New %(flag)s format specifier for argparse.add_argument help string
paul j3
report at bugs.python.org
Sun Sep 30 02:45:52 EDT 2018
paul j3 <ajipanca at gmail.com> added the comment:
https://bugs.python.org/issue13280, argparse should use the new Formatter class
Raymond Hettinger argued against making such a switch.
However there may be some value in allowing its use in parallel with the '%' style of formatting. That is, if the 'help' string has '%(...)' use the '%' formatting, if it has '{}' compatible formats use the '.format' expression. I think that can be done transparently; but I haven't tested it.
The reason I bring it up here, is that I think `.format' can provide the functionality this issue is asking for.
If I define an Action like:
a1 = parser.add_argument('--foo', '-f', default='foobar'.
help='help for {dest} or {option_strings[0]}, default is {default}'
Then:
a1.help.format(**vars(a1))
produces:
'help for foo or --foo, default is foobar'
So if there is another reason to add new style formatting to help lines, it's worth keeping this issue in mind.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34744>
_______________________________________
More information about the Python-bugs-list
mailing list