【python】argparse.add_argument中的action为‘store_true’使用说明

a.py文件的代码如下:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--t', help=' ', action='store_true', default=False)

config = parser.parse_args()

print(config.t)

直接运行python a.py,输出结果False

运行python a.py --t,输出结果True

也就是说,action='store_true',只要运行时该变量有传参就将该变量设为True。

猜你喜欢

转载自blog.csdn.net/zkq_1986/article/details/85287896