On this page
optparse.Option
Prev: optparse.make_option | Up: optparse | Next: optparse.OptionConflictError
Rel: optparse.BadOptionError, optparse.check_choice, optparse.HelpFormatter, optparse.IndentedHelpFormatter
Ref: docs.python.org — optparse.Option
Tags: #public #python3 #stdlib #optparse
Import
import optparse
from optparse import Option
Signature & Overview
optparse.Option(*opts, **attrs)
Instance attributes: _short_opts : [string] _long_opts : [string]
Methods & Attributes
Option.check_value(self, opt, value)—Option.check_valuemethod/property.Option.convert_value(self, opt, value)—Option.convert_valuemethod/property.Option.get_opt_string(self)—Option.get_opt_stringmethod/property.Option.process(self, opt, value, values, parser)—Option.processmethod/property.Option.take_action(self, action, dest, opt, value, values, parser)—Option.take_actionmethod/property.Option.takes_value(self)—Option.takes_valuemethod/property.
Usage
import optparse
opt = optparse.Option("-n", "--num", type="int", default=1)
assert opt.dest == "num" and opt.default == 1
Gotchas
- Use
parser.add_option(...)rather than constructingOptiondirectly (or migrate toargparse).
REPL Inspect
from optparse import Option
help(Option)
Linked from
Related notes
- tuts/python3/stdlib_module/optparse/make_option Linked here; links to this page; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/OptionConflictError Linked here; links to this page; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/optparse/BadOptionError Linked here; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/check_choice Linked here; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/HelpFormatter Linked here; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/IndentedHelpFormatter Linked here; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/OptionContainer shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/OptionError shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/OptionGroup shared tags: #optparse, #stdlib