图像样本数据的代码和错误:
image = Image.open(newest)
exif = image._getexif()
gps = {}
datebool = False
gpsbool = False
date = 'None'
time = 'None'
gpstext = 'None'
dmslat = 'None'
dmslon = 'None'
if exif is not None:
for tag, entry in exif.items(): #Import date and time from Exif
datebool = True
if TAGS.get(tag, tag) == 'DateTimeOriginal':
date = entry[0:10]
time = entry[11:19]
for tag, entry in exif.items(): #Check if the GPSInfo field exists
if TAGS.get(tag,tag) == 'GPSInfo':
gpsbool = True
for e in entry:
decoded = GPSTAGS.get(e,e)
print (decoded)
print(type(entry))
gps[decoded] = entry[e]
结果
4984
<type 'tuple'>
Traceback (most recent call last):File"C:Users~~~~~Desktopproject_7-8-20158_bandsProgram_camera.py", line 109, in <module>
gps[decoded] = entry[e]
IndexError: tuple index out of range
既然e是从条目中提取的,那么对条目中的特定e进行索引怎么会产生索引错误呢?我真的为gps提取了正确的数据吗?
for e in entry
不对条目中的值进行索引,而是对它们进行迭代。例如:
entry = (3, 5, 7)
for e in entry:
print(e)
将输出:
3
5
7
所以这条线可能看起来像:
gps[decoded] = e
尽管我不确定CCD_ 2线会变成什么样子。如果你真的需要枚举entry
中的项,那么你应该研究一下(我相信你会非常惊讶)enumerate()
函数。