14.3.3.5 Option attributes
The following option attributes may be passed as keyword arguments
to parser.add_option()
. If you pass an option attribute
that is not relevant to a particular option, or fail to pass a required
option attribute, optparse raises OptionError.
-
action (default:
"store"
)Determines optparse's behaviour when this option is seen on the command line; the available options are documented above.
-
type (default:
"string"
)The argument type expected by this option (e.g.,
"string"
or"int"
); the available option types are documented below. -
dest (default: derived from option strings)
If the option's action implies writing or modifying a value somewhere, this tells optparse where to write it: dest names an attribute of the
options
object that optparse builds as it parses the command line. -
default
(deprecated)The value to use for this option's destination if the option is not seen on the command line. Deprecated; use
parser.set_defaults()
instead. -
nargs
(default: 1)How many arguments of type type should be consumed when this option is seen. If > 1, optparse will store a tuple of values to dest.
-
const
For actions that store a constant value, the constant value to store.
-
choices
For options of type
"choice"
, the list of strings the user may choose from. -
callback
For options with action
"callback"
, the callable to call when this option is seen. See section 14.3.4, Option Callbacks for detail on the arguments passed tocallable
. -
callback_args
,callback_kwargs
Additional positional and keyword arguments to pass to
callback
after the four standard callback arguments. -
help
Help text to print for this option when listing all available options after the user supplies a help option (such as
"-help"
). If no help text is supplied, the option will be listed without help text. To hide this option, use the special valueSUPPRESS_HELP
. -
metavar
(default: derived from option strings)Stand-in for the option argument(s) to use when printing help text. See section 14.3.2, the tutorial for an example.
See About this document... for information on suggesting changes.