background image
3
执行脚本
$python main.py
$python main.py -h
usage: main.py [-h]
optional arguments:
-h, --help
show this help message and exit
1
2
3
4
5
6
7
上面的代码中 第一次执行 没有加参数 不输出任何内容
的二次执行 加上
-h 参数 则输出 帮助信息
上面的例子中对程序的描述比较简单,可以自己加上对程序的描述信息
import argparse
parser = argparse.ArgumentParser(description="say something abo
ut this application !!")
parser.parse_args()
1
2
3
$ python main.py -h
usage: main.py [-h]
say something about this application !!
optional arguments: