[Python-ideas] argparse - add support for environment variables
Miki Tebeka
miki.tebeka at gmail.com
Tue Mar 19 00:02:33 CET 2013
OK, so what's next in process? Got some +1 and some -1, how do we proceed?
(or not).
On Tuesday, February 19, 2013 8:03:16 AM UTC-8, Miki Tebeka wrote:
>
> 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/20130318/379c0938/attachment.html>
More information about the Python-ideas
mailing list