argparse.ArgumentParser()
argparse.ArgumentParser() is a Python function in the Argparse Module category. Creates an argument parser for processing command-line arguments. The syntax is argparse.ArgumentParser(prog=None, usage=None, description=None, epilog=None, formatter_class=argparse.HelpFormatter, add_help=True, allow_abbrev=True). Returns: ArgumentParser object. A typical example: import argparse
parser = argparse.ArgumentParser(description="Process files")
parser.add_argument("input", help="input file")
parser.add_argument("--output", "-o", help="output file")
args = parser.parse_args()
print(args.input). A close sibling is argparse.add_argument(), which defines a command-line argument the parser should accept. A close sibling is argparse.parse_args(), which parses the command-line arguments and returns a Namespace object. A close sibling is argparse.Namespace, which the default namespace object used by parse_args(). More about this category: Command-line argument parsing — ArgumentParser, add_argument. For a broader walkthrough, read the Argparse Module guide. Related Argparse Module entries: argparse.add_argument(), argparse.parse_args(), argparse.Namespace. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try argparse.ArgumentParser() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.