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

Eli Bendersky eliben at gmail.com
Wed Feb 20 05:29:48 CET 2013


On Tue, Feb 19, 2013 at 3:51 PM, Miki Tebeka <miki.tebeka 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?


> The other reason is that it's making common code shorter, which is a win
> IMO.
>

How common is such code? YMMV here... I don't think it's nearly common
enough to warrant adding complexity to a stdlib module in order to
implement a non-orthogonal feature.

In general, I'm -1 on the idea. argparse is for parsing command line
arguments. Python provides you convenient access to env vars via
os.environ. Why mix up the two?

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


More information about the Python-ideas mailing list