Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在参数解析器中传递图像目录的路径?_Python_Parsing_Arguments - Fatal编程技术网

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设置标志是什么意思?你能根据问题>给出一个例子吗?我面临同样的问题。你能解决这个问题吗?