设置参数:

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...

pycharm处理命令行参数

 在Parameters中填写自己需要的参数:

pycharm处理命令行参数

 这样需要提供参数的代码既可以直接运行也可以debug

相关文章:

  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-12-23
  • 2021-06-19
  • 2021-09-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-11-06
  • 2021-10-24
  • 2021-06-20
  • 2022-01-31
相关资源
相似解决方案