Python 如何在参数解析器中传递图像目录的路径?
我有一个包含一组图像的文件夹。如何将它的路径传递给参数解析器,我已通过以下方式构造了参数解析器:Python 如何在参数解析器中传递图像目录的路径?,python,parsing,arguments,Python,Parsing,Arguments,我有一个包含一组图像的文件夹。如何将它的路径传递给参数解析器,我已通过以下方式构造了参数解析器: ap = argparse.ArgumentParser() ap.add_argument("-i", "--images", required=True, help="path to images directory") args = vars(ap.parse_args()) 我想通过的路径是home/downloads/images 目前我遇到以下错误: usage: detect.py
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True, help="path to images directory")
args = vars(ap.parse_args())
我想通过的路径是home/downloads/images
目前我遇到以下错误:
usage: detect.py [-h] -i IMAGES
detect.py: error: the following arguments are required: -i/--images
试试这个:
from argparse import ArgumentParser
parser = ArgumentParser(description='Demo: import images')
parser.add_argument('-i', '--images',
nargs='?',
required=True,
help='path to images directory')
args = parser.parse_args()
print("Bingo:", args.images)
这样称呼:
./detect.py -i home/downloads/images
你没有设置标志。如果是,请提供脚本崩溃时的shell。@HampusLarsson设置标志是什么意思?你能根据问题>给出一个例子吗?我面临同样的问题。你能解决这个问题吗?