argparse — Parser for command-line options, arguments and subcommands

Added in version 3.2.

源代码: Lib/argparse.py


The argparse 模块使编写用户友好的命令行接口变得容易。程序定义它要求什么自变量,和 argparse 会弄明白如何剖析出那些从 sys.argv argparse module also automatically generates help and usage messages. The module will also issue errors when users give the program invalid arguments.

The argparse module’s support for command-line interfaces is built around an instance of argparse.ArgumentParser . It is a container for argument specifications and has options that apply to the parser as whole:

parser = argparse.ArgumentParser(
                    prog='ProgramName',
                    description='What the program does',
                    epilog='Text at the bottom of help')