Argparse中action的可选参数store_true,store_false
store_true 是指带触发action时为真,不触发则为假, 代码去掉default初始化,其功能也不会变化
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(无触发)
如果这篇文章帮助到了你,你可以请作者喝一杯咖啡

浙公网安备 33010602011771号