[Python-ideas] Fwd: argparse - add support for environment variables
Miki Tebeka
miki.tebeka at gmail.com
Wed Feb 20 19:10:33 CET 2013
On Tuesday, February 19, 2013 8:29:48 PM UTC-8, Eli Bendersky wrote:
>
> On Tue, Feb 19, 2013 at 3:51 PM, Miki Tebeka <miki.... at gmail.com<javascript:>
> > wrote:
>
>>
>> Why not:
>>>
>>> parser.add_argument('--spam', default=os.environ.get('SPAM', 7))
>>>
>> Mainly because then you can't swap in different dictionaries to resolve
>> SPAM (when specifying "env" to ArgumentParser).
>>
>
> Can you elaborate on this requirement?
>
Sure. The idea is the you have some kind of "parameter resolution" (very
much like the interpreter is resolving variables). You first look into the
command line, and if not found you query a dictionary. Most times, this
dictionary will be os.environ. However you can pass your own dictionary to
resolve the parameters (for testing, configuration files). You can even use
something like Raymonds Nested Contexts<http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/>for that matter.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130220/c2e3e1c0/attachment.html>
More information about the Python-ideas
mailing list