On this page
argparse.MetavarTypeHelpFormatter
Prev: argparse.HelpFormatter | Up: argparse | Next: argparse.Namespace
Rel: argparse.Action, argparse.ArgumentDefaultsHelpFormatter, argparse.ArgumentError, argparse.ArgumentParser
Ref: docs.python.org — argparse.MetavarTypeHelpFormatter
Tags: #public #python3 #stdlib #argparse
Import
import argparse
from argparse import MetavarTypeHelpFormatter
Signature & Overview
argparse.MetavarTypeHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None, color=True)
Help message formatter which uses the argument 'type' as the default metavar value (instead of the argument 'dest') Only the name of this class is considered a public API. All the methods
Methods & Attributes
MetavarTypeHelpFormatter.add_argument(self, action)—MetavarTypeHelpFormatter.add_argumentmethod/property.MetavarTypeHelpFormatter.add_arguments(self, actions)—MetavarTypeHelpFormatter.add_argumentsmethod/property.MetavarTypeHelpFormatter.add_text(self, text)—MetavarTypeHelpFormatter.add_textmethod/property.MetavarTypeHelpFormatter.add_usage(self, usage, actions, groups, prefix=None)—MetavarTypeHelpFormatter.add_usagemethod/property.MetavarTypeHelpFormatter.end_section(self)—MetavarTypeHelpFormatter.end_sectionmethod/property.MetavarTypeHelpFormatter.format_help(self)—MetavarTypeHelpFormatter.format_helpmethod/property.MetavarTypeHelpFormatter.start_section(self, heading)—MetavarTypeHelpFormatter.start_sectionmethod/property.
Usage
import argparse
p = argparse.ArgumentParser(formatter_class=argparse.MetavarTypeHelpFormatter)
p.add_argument("--retries", type=int, help="Max attempts")
assert "--retries int" in p.format_help()
Gotchas
- Requires
type=to have a__name__: Usestype.__name__as the metavar instead of uppercasingdest; fails iftype=is a lambda orfunctools.partial.
REPL Inspect
from argparse import MetavarTypeHelpFormatter
help(MetavarTypeHelpFormatter)
Linked from
Related notes
- tuts/python3/stdlib_module/argparse/HelpFormatter Linked here; links to this page; shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/Namespace Linked here; links to this page; shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/argparse/Action Linked here; shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/ArgumentDefaultsHelpFormatter Linked here; shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/ArgumentError Linked here; shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/ArgumentParser Linked here; shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/ArgumentTypeError shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/BooleanOptionalAction shared tags: #argparse, #stdlib
- tuts/python3/stdlib_module/argparse/FileType shared tags: #argparse, #stdlib