I am getting a named list as an output from a Python program.
[{'path': u'/home/mycomp/Documents/folder1/906350_16379886.JPG', 'score': 7.937254, 'dist': 0.0, 'id': u'AWW3yZOubIicFyUL0_lv', 'metadata': None}, {'path': u'/home/mycomp/Documents/folder1/907675_16389607.JPG', 'score': 0.5119519, 'dist': 0.2922064602034243, 'id': u'AWW3bhtybIicFyUL0uVN', 'metadata': None}]
The length of the output in this case is 2 and I do not have control on the length of the output. I want to get only the filename from the path printed. I understand i can use
os.path.basename(path)
to get the filename. However, when I tried getting the path from the list using the following code:
for (i, imagePath) in enumerate(imagePaths):
a=ses.search_image(imagePath)
for k,v in enumerate(a):
print(v)
imagePath = provides the path to the image
a=ses.search_image(imagePath) = searches for similar image and stores all the matching image parameters for the image in the path to a. That output of a is what I have given above.
for k,v in enumerate(a):
print(v)
actually prints each list as a separate line like this:
{'path': u'/home/mycomp/Documents/folder1/906350_16379886.JPG', 'score': 7.937254, 'dist': 0.0, 'id': u'AWW3yZOubIicFyUL0_lv', 'metadata': None}
{'path': u'/home/mycompDocuments/folder1/907675_16389607.JPG', 'score': 0.5119519, 'dist': 0.2922064602034243, 'id': u'AWW3bhtybIicFyUL0uVN', 'metadata': None}
The desired output is just this:
906350_16379886.JPG
907675_16389607.JPG