【发布时间】:2018-06-10 18:52:39
【问题描述】:
我正在尝试返回图片路径,如下:
from imutils import paths
import argparse
# create parser
parser = argparse.ArgumentParser()
# define the command-line options
parser.add_argument('--dataset', required=True,help='path to the dataset')
# read the command-line arguments and interpret them
args = parser.parse_args()
imagePath = paths.list_images(args['dataset'])
print imagePath
但是,得到以下错误:
Traceback (most recent call last):
File "test.py", line 11, in <module>
imagePath = paths.list_images(args['dataset'])
TypeError: 'Namespace' object has no attribute '__getitem__'
我通过输入以下命令运行脚本:
$ python test.py --dataset /images
知道我在这里做错了什么吗?
谢谢。
【问题讨论】:
-
args是argparse.Namespace对象,而不是字典。你想要一个属性。发送print(args)以更清楚地了解它是什么。
标签: python image parsing path argparse