
Feb. 19, 2013
10:03 a.m.
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