只是试图从一堆照片的 EXIF 数据中提取一些纬度/经度信息,但代码会抛出 a ,KeyError即使稍后(成功)使用该键来打印特定坐标。
有问题的字典是“ tags” -'GPS GPSLatitude'并且'GPS GPSLongitude'都是tags.keys(); 我已经三重检查了。
那么对于为什么会抛出关键错误有什么直觉tags['GPS GPSLatitude']吗tags['GPS GPSLongitude']?
import os
import exifread
output = dict()
output['name'] = []
output['lon'] = []
output['lat'] = []
for file in os.listdir(path):
if file.endswith(".JPG"):
full_path = path + file
print (file) #check to ensure all files were found
output['name'].append(file) #append photo name to dictionary
f = open(full_path, 'rb') #open photo
tags = exifread.process_file(f) #read exifdata …Run Code Online (Sandbox Code Playgroud)