[Python-ideas] argparse - add support for environment variables
Miki Tebeka
miki.tebeka at gmail.com
Tue Feb 19 17:03:16 CET 2013
Greetings,
The usual way of resolving configuration is command line -> environment ->
default.
Currently argparse supports only command line -> default, I'd like to
suggest an optional "env" keyword to add_argument that will also resolve
from environment. (And also optional env dictionary to the ArgumentParser
__init__ method [or to parse_args], which will default to os.environ).
Example:
[spam.py]
parser = ArgumentParser()
parser.add_argument('--spam', env='SPAM', default=7)
args = parser.parse_args()
print(args.spam)
./spam.py -> 7
./spam.py --spam=12 -> 12
SPAM=9 ./spam.py -> 9
SPAM=9 ./spam.py --spam=12 -> 12
What do you think?
--
Miki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130219/bc6656a4/attachment.html>
More information about the Python-ideas
mailing list