設置參數:
ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="path to input image") ap.add_argument("-t", "--template", required=True, help="path to template OCR-A image") args = vars(ap.parse_args())
代碼中如有參數要求必須要提供,否則運行出錯,甚至debug也不行
可以用命令行執行代碼並提供參數:
python xxx.py -i 參數1 -t 參數2
但是這樣還是不能debug,這時可以用pycharm來設置:
Run-->Edit Configurations...
在Parameters中填寫自己需要的參數:
這樣需要提供參數的代碼既可以直接運行也可以debug