On this page
optparse.OptionGroup
Prev: optparse.OptionError | Up: optparse | Next: optparse.OptionParser
Rel: optparse.BadOptionError, optparse.check_choice, optparse.HelpFormatter, optparse.IndentedHelpFormatter
Ref: docs.python.org — optparse.OptionGroup
Tags: #public #python3 #stdlib #optparse
Import
import optparse
from optparse import OptionGroup
Signature & Overview
optparse.OptionGroup(parser, title, description=None)
optparse.OptionGroup class.
Methods & Attributes
OptionGroup.add_option(self, *args, **kwargs)— add_option(opt_str, ..., kwarg=val, ...)OptionGroup.add_options(self, option_list)—OptionGroup.add_optionsmethod/property.OptionGroup.destroy(self)— see OptionParser.destroy().OptionGroup.format_description(self, formatter)—OptionGroup.format_descriptionmethod/property.OptionGroup.format_help(self, formatter)—OptionGroup.format_helpmethod/property.OptionGroup.format_option_help(self, formatter)—OptionGroup.format_option_helpmethod/property.OptionGroup.get_description(self)—OptionGroup.get_descriptionmethod/property.OptionGroup.get_option(self, opt_str)—OptionGroup.get_optionmethod/property.OptionGroup.has_option(self, opt_str)—OptionGroup.has_optionmethod/property.OptionGroup.remove_option(self, opt_str)—OptionGroup.remove_optionmethod/property.OptionGroup.set_conflict_handler(self, handler)—OptionGroup.set_conflict_handlermethod/property.OptionGroup.set_description(self, description)—OptionGroup.set_descriptionmethod/property.OptionGroup.set_title(self, title)—OptionGroup.set_titlemethod/property.
Usage
import optparse
p = optparse.OptionParser()
grp = optparse.OptionGroup(p, "Debug Options")
grp.add_option("-d", action="store_true", dest="debug")
p.add_option_group(grp)
assert "Debug Options:" in p.format_help()
Gotchas
- Groups related flags in
--helpoutput (equivalent toargparse.add_argument_group()).
REPL Inspect
from optparse import OptionGroup
help(OptionGroup)
Linked from
Related notes
- tuts/python3/stdlib_module/optparse/OptionError Linked here; links to this page; shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/OptionParser 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/make_option shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/Option shared tags: #optparse, #stdlib
- tuts/python3/stdlib_module/optparse/OptionConflictError shared tags: #optparse, #stdlib