Argparse中action的可选参数store_true,store_false

store_true 是指带触发action时为真,不触发则为假, 代码去掉default初始化,其功能也不会变化python

 

parser.add_argument('-c', action='store_true')# 或者parser.add_argument('-c', action='store_true', default=false)

#python test.py -c => c是true(触发)

#python test.py => c是false(无触发)
相关文章
相关标签/搜索