input and output in this exampletwo types of options are added the first option- or --outputhas required argument this behavior is selected by specifying action='storein the call to add_option(the second option- or --debugis merely setting boolean flag this is enabled by specifying action='store_truein add_option(the dest argument to add_option(selects an attribute name where the argument value will be stored after parsing the set_defaults(method sets default values for one or more of the options the argument names used with this method should match the destination names selected for each option if no default value is selectedthe default value is set to none the previous program recognizes all of the following command-line stylespython prog py - outfile - infile infilen python prog py --output=outfile --debug infile infilen python prog py - python prog py --help parsing is performed using the parse_args(method this method returns -tuple (optsargswhere opts is an object containing the parsed option values and args is list of items on the command line not parsed as options option values are retrieved using opts dest where dest is the destination name used when adding an option for examplethe argument to the - or --output argument is placed in opts outfilewhereas args is list of the remaining arguments such as ['infile ''infilen'the optparse module automatically provides - or --help option that lists the available options if requested by the user bad options also result in an error message this example only shows the simplest use of the optparse module further details on some of the more advanced options can be found in "operating system services environment variables environment variables are accessed in the dictionary os environ here' an exampleimport os path os environ["path"user os environ["user"editor os environ["editor"etc to modify the environment variablesset the os environ variable for exampleos environ["foo""barmodifications to os environ affect both the running program and subprocesses created by python files and file objects the built-in function open(name [,mode [,bufsize]]opens and creates file objectas shown heref open("foo" open("foo",' ' open("foo",' 'opens "foofor reading opens "foofor reading (same as aboveopen for writing lib fl ff