The first step in using optparse is to create an OptionParser instance:
parser = OptionParser(...)
The OptionParser constructor has no required arguments, but a number of optional keyword arguments. You should always pass them as keyword arguments, i.e. do not rely on the order in which the arguments are declared.
usage (default: "%prog [options]")%prog to os.path.basename(sys.argv[0]) (or to prog if
you passed that keyword argument). To suppress a usage message,
pass the special value optparse.SUPPRESS_USAGE.
option_list (default: [])option_list are added after any options in
standard_option_list (a class attribute that may be set by
OptionParser subclasses), but before any version or help options.
Deprecated; use add_option() after creating the parser instead.
option_class (default: optparse.Option)version (default: None)version, optparse automatically adds
a version option with the single option string --version. The
substring "%prog" is expanded the same as for usage.
conflict_handler (default: "error")description (default: None)usage, but before
the list of options).
formatter (default: a new IndentedHelpFormatter)add_help_option (default: True)"-h"
and --help) to the parser.
prog"%prog" in usage and
version instead of os.path.basename(sys.argv[0]).
See About this document... for information on suggesting changes.