[issue26394] argparse: Add set_values() function to complement set_defaults()

Michael Herold report at bugs.python.org
Sat Feb 20 11:17:11 EST 2016


New submission from Michael Herold:

argparse has at least three features to set defaults (default=, set_defaults(),  argument_default=). However, there is no feature to set the values of arguments.

The difference is, that a required argument has to be specified, also if a default value exists. Thus, a clean way to set values from config files or env variables does not exist without making all arguments optional.

See for example <http://stackoverflow.com/questions/10551117/setting-options-from-environment-variables-when-using-argparse>, where it becomes clear that no general solution for all actions exists. As a result, people also start to mess around with the args parameter of parse_args(). Even ConfigArgParse (used by Let's Encrypt) seems to fail in doing this properly.

So please add a set_values() function, similar to set_defaults(). The predefined value should be treated as if it had been entered on the command line. If the value has also been supplied via the command line, the predefined value is overwritten.

----------
components: Library (Lib)
messages: 260568
nosy: quabla
priority: normal
severity: normal
status: open
title: argparse: Add set_values() function to complement set_defaults()
type: enhancement
versions: Python 3.5

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


More information about the Python-bugs-list mailing list