pycharm处理命令行参数

设置参数:

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

原文地址:https://www.cnblogs.com/SCCQ/p/12298740.html