Python 2.7 我不知道';我不明白为什么我';当试图提取exif数据时,出现索引错误

Python 2.7 我不知道';我不明白为什么我';当试图提取exif数据时,出现索引错误,python-2.7,gps,exif,Python 2.7,Gps,Exif,来自图像的样本数据的代码和错误: 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():

来自图像的样本数据的代码和错误:

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\~~~~~\Desktop\project_7-8-2015\8_bands\Program_camera.py", line 109, in <module>
gps[decoded] = entry[e]
IndexError: tuple index out of range
4984
回溯(最近一次调用):文件“C:\Users\~~~~~\Desktop\project\u 7-8-2015\8\u bands\Program\u camera.py”,第109行,在
gps[解码]=条目[e]
索引器错误:元组索引超出范围

既然e是从条目中提取的,那么从条目中索引特定的e如何生成索引错误呢?我真的为gps提取了正确的数据吗?

对于条目中的e
没有索引条目中的值,而是对它们进行迭代。例如:

entry = (3, 5, 7)
for e in entry:
    print(e)
将输出:

3
5
7
所以这条线应该看起来像:

gps[decoded] = e
虽然我不确定GPSTAGS行会变成什么样子。如果您确实需要枚举
entry
中的项目,那么您应该研究
enumerate()
函数