[Python-ideas] Fwd: argparse - add support for environment variables

Eli Bendersky eliben at gmail.com
Thu Feb 21 01:18:50 CET 2013


On Wed, Feb 20, 2013 at 10:10 AM, Miki Tebeka <miki.tebeka at gmail.com> wrote:

>
>
> 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> 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.
>

What about config files? Mix them into argparse too? Oh, and support for
.ini/XML/YAML/JSON/sqlite configs, please!

Sarcasm aside (don't take it personally ;-), my point is this: argparse is
a nice, orthogonal library for dealing with command-line arguments. Let's
keep it this way. Python gives you tools to *very easily* mix up different
configuration paths, with really minimal effort.

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130220/b1e38ffb/attachment.html>


More information about the Python-ideas mailing list