import argparse parser = argparse.ArgumentParser() parser.add_argument("--aa", type=int, help="The number of clients to write from for each ip", required=True) parser.add_argument("--bb", type=int, help="The number of seconds to run for each ip", required=True) args = parser.parse_args() AA = args.aa BB = args.bb print(AA,BB)
1、正常的输入
D:\python\test\>python zz.py --aa 2 --bb 25 2 25
2、错误的输入的提示
D:\python\test\>python zz.py --aa 2 usage: zz.py [-h] --aa AA --bb BB zz.py: error: the following arguments are required: --bb
3、脚本的-h的提示
D:\python\test\>python zz.py -h usage: zz.py [-h] --aa AA --bb BB optional arguments: -h, --help show this help message and exit --aa AA The number of clients to write from for each ip --bb BB The number of seconds to run for each ip