Python3.7 - Argparse模块讲解
https://www.jianshu.com/p/00425f6c0936讲的很有趣。
argparse是一个命令行参数解析模块。
代码中注意是 --ParA 还是 ParA
import argparse
parser = argparse.ArgumentParser()
parser.description="calculate the product of two integers"
parser.add_argument("--ParA", help="I am number A", type=int)
parser.add_argument("--ParB", help="I am number B", type=int)
args = parser.parse_args()
if args.ParA:
print('received ParA:', args.ParA)
if args.ParB:
print('received ParB:', args.ParB)
if args.ParB and args.ParA:
print('So the product of', args.ParA, 'and', args.ParB, 'is', args.ParA*args.ParB)

浙公网安备 33010602011771号