argparse
import argparse
# ArgumentParser
parser = argparse.ArgumentParser()
parser.add_argument('-all', action="store_true")
parser.add_argument('-task', help='==> your task')
parser.add_argument('-file', help='==> file path')
args = parser.parse_args()
# 使用 -h 時會顯示 help 內容
參考資料: https://medium.com/@dboyliao/python-超好用標準函式庫-argparse-4eab2e9dcc69
設定action="store_true",表示若使用該參數時則帶入True
#python test.py -c => c是true(觸發)
#python test.py => c是false(無觸發)
Last updated
Was this helpful?