2017-12-30 97 views
0

は、私は次のように、画像のパスを返すようにしようとしているリスト画像パス「名前空間」オブジェクトが属性を持っていない「__getitem__」

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 

任意のアイデアをやっている:

私は、次のコマンドを入力して、スクリプトを実行しましたか?

ありがとうございました。

+1

'args'は辞書ではなく' argparse.Namespace'オブジェクトです。属性が必要です。それが何であるかをより明確にするために 'print(args)'を実行してください。 – hpaulj

答えて

0

これは

imagePath = paths.list_images(args.dataset) 

を動作するはずそれとも、必要な場合は、何らかの理由でのdict:

imagePath = paths.list_images(args.__dict__['dataset']) 
+0

お返事ありがとうございます。 "File" test.py "、11行目、 imagePath = paths.list_images(args.dataset) AttributeError: 'dict'オブジェクトに 'dataset'属性がありません" – Simplicity

+0

"File" test.py "、11行目、 imagePath = paths.list_images(args .__ dict __ ['dataset']) AttributeError: 'dict'オブジェクトに属性がありません'__dict__' " – Simplicity

+0

@シンプリシティre:#1 - それは変です、argparseのバージョンは何ですか?あなたは最初の問題の原因で報告されたオブジェクトのタイプを報告していませんでしたが報告されたオブジェクトのタイプはdictではありませんでしたが、名前空間:#2 - エラーメッセージから '.dict'を入れたようですそれは '.__ dict__'でなければなりません – Ivan

0

私が働いてプログラムを取得するには、次の(vars()に注意してください)でした:

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 = vars(parser.parse_args()) 

print args 

imagePath = paths.list_images(args['dataset']) 

for image in imagePath: 
    print image 
関連する問題