argparse.parse_args()
argparse.parse_args() is a Python method in the Argparse Module category. Parses the command-line arguments and returns a Namespace object. The syntax is argparse.parse_args(args=None, namespace=None). Parameters: args — strings to parse (default: sys.argv[1:]). Returns: Namespace object. A typical example: args = parser.parse_args(["--output", "out.txt", "in.txt"])
args.output # "out.txt"
args.input # "in.txt". A close sibling is argparse.ArgumentParser(), which creates an argument parser for processing command-line arguments. A close sibling is argparse.add_argument(), which defines a command-line argument the parser should accept. 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.ArgumentParser(), argparse.add_argument(), 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.parse_args() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.