argparse.ArgumentParser

class argparse.ArgumentParser(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)[source]

Object for parsing command line strings into Python objects.

Keyword Arguments:
  • prog – The name of the program (default: sys.argv[0])

  • usage – A usage message (default: auto-generated from arguments)

  • description – A description of what the program does

  • epilog – Text following the argument descriptions

  • parents – Parsers whose arguments should be copied into this one

  • formatter_class – HelpFormatter class for printing help messages

  • prefix_chars – Characters that prefix optional arguments

  • fromfile_prefix_chars – Characters that prefix files containing

    additional arguments

  • argument_default – The default value for all arguments

  • conflict_handler – String indicating how to handle conflicts

  • add_help – Add a -h/-help option

Methods

__format__ default object formatter
__init__([prog, usage, description, epilog, ...])
__new__((S, ...)
__reduce__ helper for pickle
__reduce_ex__ helper for pickle
__repr__()
__sizeof__(() -> int) size of object in memory, in bytes
__subclasshook__ Abstract classes can override this to customize issubclass().
_add_action(action)
_add_container_actions(container)
_check_conflict(action)
_check_value(action, value)
_get_args()
_get_formatter()
_get_handler()
_get_kwargs()
_get_nargs_pattern(action)
_get_option_tuples(option_string)
_get_optional_actions()
_get_optional_kwargs(*args, **kwargs)
_get_positional_actions()
_get_positional_kwargs(dest, **kwargs)
_get_value(action, arg_string)
_get_values(action, arg_strings)
_handle_conflict_error(action, ...)
_handle_conflict_resolve(action, ...)
_match_argument(action, arg_strings_pattern)
_match_arguments_partial(actions, ...)
_parse_known_args(arg_strings, namespace)
_parse_optional(arg_string)
_pop_action_class(kwargs[, default])
_print_message(message[, file])
_read_args_from_files(arg_strings)
_registry_get(registry_name, value[, default])
_remove_action(action)
add_argument(dest, ...[, name, name])
add_argument_group(*args, **kwargs)
add_mutually_exclusive_group(**kwargs)
add_subparsers(**kwargs)
convert_arg_line_to_args(arg_line)
error(message: string) Prints a usage message incorporating the message to stderr and exits.
exit([status, message])
format_help()
format_usage()
format_version()
get_default(dest)
parse_args([args, namespace])
parse_known_args([args, namespace])
print_help([file])
print_usage([file])
print_version([file])
register(registry_name, value, object)
set_defaults(**kwargs)