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....@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 for that matter.