小编E. *_*ase的帖子

当键在字典中时出现键错误

只是试图从一堆照片的 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)

python exif keyerror

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

exif ×1

keyerror ×1

python ×1