New submission from Eric McDonald:

There are several use cases for having the equivalent of the 
optparse.OptionParser 'get_option' method and the 'option_groups' and 
'option_list' properties in argparse.ArgumentParser class.

(1) Easy alteration of the text of the default help option. With optparse, one 
could write:

>>> oparser.get_option( "-h" ).help
'show this help message and exit'
>>> oparser.get_option( "-h" ).help = "Show this help message and exit."
>>> oparser.get_option( "-h" ).help
'Show this help message and exit.'

The equivalent facility does not appear to exist in argparse. (Issue #19462, 
http://bugs.python.org/issue19462, is about a different use case. And, while 
https://docs.python.org/3/library/argparse.html#add-help suggests a workaround 
with add_help=False and then creating a new option with the 'help' action, it 
is still less convenient than altering the existing help option.)

(2) Inspection of all the argument declarations in an ArgumentParser object 
after it has been populated. This is particularly useful if you want to look 
for the equivalent of the available options in config files and don't want to 
have write explicit code which separately enumerates the available config file 
keys and how to handle them. With an OptionParser, one could use the 
'option_groups' attribute to find all option groups (to correspond to config 
file sections) and the 'option_list' attribute to find all options (to 
correspond to config file keys); these are all part of the published interface 
and provide relatively simple data types to inspect. With an Argument Parser, 
one needs to rely upon the unpublished interface (the '_actions' attribute of a 
parser, etc...).

----------
components: Library (Lib)
messages: 233394
nosy: emcd
priority: normal
severity: normal
status: open
title: argparse: Provide equivalent of 
optparse.OptionParser.{option_groups,option_list,get_option}
type: enhancement
versions: Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23159>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to