Primary
argparse.ArgumentParser() ⚬|Documentation|1st|20260122195929-00-⌔
class
argparse.ArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=argparse.HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True, ﹡, suggest_on_error=False, color=True)Create a new
ArgumentParserobject. All parameters should be passed as keyword arguments. Each parameter has its own more detailed description below, but in short they are:
- prog - The name of the program (default: generated from the
__main__module attributes andsys.argv[0])- usage - The string describing the program usage (default: generated from arguments added to parser)
- description - Text to display before the argument help (by default, no text)
- epilog - Text to display after the argument help (by default, no text)
- parents - A list of
ArgumentParserobjects whose arguments should also be included- formatter_class - A class for customizing the help output
- prefix_chars - The set of characters that prefix optional arguments (default: ‘-‘)
- fromfile_prefix_chars - The set of characters that prefix files from which additional arguments should be read (default:
None)- argument_default - The global default value for arguments (default:
None)- conflict_handler - The strategy for resolving conflicting optionals (usually unnecessary)
- add_help - Add a
-h/--helpoption to the parser (default:True)- allow_abbrev - Allows long options to be abbreviated if the abbreviation is unambiguous (default:
True)- exit_on_error - Determines whether or not
ArgumentParserexits with error info when an error occurs. (default:True)- suggest_on_error - Enables suggestions for mistyped argument choices and subparser names (default:
False)- color - Allow color output (default:
True)Changed in version 3.5: allow_abbrev parameter was added.
Changed in version 3.8: In previous versions, allow_abbrev also disabled grouping of short flags such as
-vvto mean-v -v.Changed in version 3.9: exit_on_error parameter was added.
Changed in version 3.14: suggest_on_error and color parameters were added.
The following sections describe how each of these are used.
Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •