optparse

A powerful, extensible, and easy-to-use option parser.

By Greg Ward <gward@python.net>

Originally distributed as Optik.

For support, use the optik-users@lists.sourceforge.net mailing list (http://lists.sourceforge.net/lists/listinfo/optik-users).

Simple usage example:

from optparse import OptionParser

parser = OptionParser() parser.add_option(“-f”, “–file”, dest=”filename”,

help=”write report to FILE”, metavar=”FILE”)
parser.add_option(“-q”, “–quiet”,
action=”store_false”, dest=”verbose”, default=True, help=”don’t print status messages to stdout”)

(options, args) = parser.parse_args()

Functions

check_builtin(option, opt, value)
check_choice(option, opt, value)
gettext(message)
isbasestring(x)

Classes

HelpFormatter(indent_increment, ...) Abstract base class for formatting option help.
IndentedHelpFormatter([indent_increment, ...]) Format help with indented section bodies.
Option(*opts, **attrs) Instance attributes:
OptionContainer(option_class, ...) Abstract base class.
OptionGroup(parser, title[, description])
OptionParser([usage, option_list, ...]) Class attributes: standard_option_list : [Option] list of standard options that will be accepted by all instances of this parser class (intended to be overridden by subclasses).
TitledHelpFormatter([indent_increment, ...]) Format help with underlined section headers.
Values([defaults])
make_option alias of Option

Exceptions

AmbiguousOptionError(opt_str, possibilities) Raised if an ambiguous option is seen on the command line.
BadOptionError(opt_str) Raised if an invalid option is seen on the command line.
OptParseError(msg)
OptionConflictError(msg, option) Raised if conflicting options are added to an OptionParser.
OptionError(msg, option) Raised if an Option instance is created with invalid or inconsistent arguments.
OptionValueError(msg) Raised if an invalid option value is encountered on the command line.