今天我们讲解:argparse.ArgumentParser
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-batchsize", required=True, help="batchsize set")
args = vars(ap.parse_args())
print(args["batchsize"])
执行测试代码:
(base) user@ubuntu:~$ python test.py -batchsize 64
64
(base) user@ubuntu:~$ python test.py -h
usage: test.py [-h] -batchsize BATCHSIZE
optional arguments:
-h, --help show this help message and exit
-batchsize BATCHSIZE batchsize set
更多可以学习添加链接描述