python – TypeError:’int’对象是unsubscriptable

python中我收到此错误:

TypeError: 'int' object is unsubscriptable

这发生在以下行:

sectorcalc[i][2]= ((today[2]/yesterday[2])-1)

我无法在任何地方为python找到unsubscriptable的好定义.

for quote in sector[singlestock]:
        i+=1
        if i < len(sector):
            if i==0:
                sectorcalc[i][0]= quote[0]
                sectorcalc[i][2]= 0
                sectorcalc[i][3]= 0
                sectorcalc[i][4]= 0
                sectorcalc[i][5]= 0
                sectorcalc[i][6]= 0
                sectorcalc[i][7]= 0
            else:                    
                yesterday = sector[singlestock-1][i]

                print yesterday                                

                today = quote

                print type(today[2])
                sectorcalc[i][2]= ((today[2]/yesterday[2])-1)
                sectorcalc[i][3]= (today[3]/yesterday[3])-1
                sectorcalc[i][4]= (today[4]/yesterday[4])-1
                sectorcalc[i][5]= (today[5]/yesterday[5])-1 
                sectorcalc[i][6]= (today[6]/yesterday[6])-1
                sectorcalc[i][7]= (today[7]/yesterday[7])-1

这个错误是什么意思?

今天[2]中的“[2]”称为下标.

This usage is possible only if “today”
is a sequence type. Native sequence
types – List, string, tuple etc

由于您收到错误 – ‘int’对象是不可取消的.这意味着“今天”不是序列而是int类型对象.

当你期望一个序列时,你需要找到/调试为什么“今天”或“昨天”是一个int类型的对象.

[编辑:说清楚]

Error can be in

> sectorcalc [i]
>今天(已经证明是一个清单)
>昨天

翻译自:https://stackoverflow.com/questions/4060572/typeerror-int-object-is-unsubscriptable

转载注明原文:python – TypeError:’int’对象是unsubscriptable