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(無觸發)
相關文章
相關標籤/搜索