如何在python(spyder)中解析参数?

问题描述 投票:3回答:1

我正在关注this教程,并尝试运行脚本的以下部分。我正在使用python 3.7和spyder 3.3.4。

ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
    help="path to input dataset (i.e., directory of images)")
ap.add_argument("-m", "--model", required=True,
    help="path to output model")
ap.add_argument("-l", "--labelbin", required=True,
    help="path to output label binarizer")
ap.add_argument("-p", "--plot", type=str, default="plot.png",
    help="path to output accuracy/loss plot")
args = vars(ap.parse_args())

我尝试过按文件运行>配置,并按照this post andthis post的建议输入参数。

命令行选项:path1path2path3path4

我为上面的参数填写了适当的路径,然后运行了脚本,但出现以下错误。

用法:train.py [-h] -d数据集-m模型-l LABELBIN [-p图]train.py:错误:需要以下参数:-d /-dataset,-m /-模型,-l /-labelbin发生了异常,请使用%tb查看完整的回溯。SystemExit:2

如何解决此错误以正确运行脚本并在spyder中传递参数?

python python-3.x arguments spyder argparse
1个回答
1
投票

您可以通过从设置中进行特殊运行并按预期顺序排列参数来解析参数。

© www.soinside.com 2019 - 2024. All rights reserved.