Getopt: Using Environment Var To Override

Tim Daneliuk tundra at
Fri Jan 3 22:10:07 CET 2003

I currently use getopt to process my command line args.  Is there some
standard/easy/idiomatic/Pythonic way to supplement this with an environment
variable?  I want the user to be able set options one of several ways:

          1) Do nothing, accept program defaults.
          2) Override program defaults with an environment variable
             which contains desired defaults.
          3) Override both program and env var defaults with command
             line arguments.

1) and 3) are in place today.  I'd like to add 2) without having to manually
parse the environment string myself.  I guess what I'm asking is where there
is a way to feed getopt the contents of an environment variable after
it has processed the command line?
Tim Daneliuk
tundra at

More information about the Python-list mailing list