본문 바로가기
파이썬

파이썬 TypeError : 'int'개체는 구독 할 수 없습니다.

by º기록 2020. 10. 26.
반응형

파이썬에서는이 오류가 발생합니다.

TypeError: 'int' object is unsubscriptable

이것은 라인에서 발생합니다.

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

나는 어디서나 파이썬에 대한 구독 불가의 좋은 정의를 찾을 수 없었습니다.

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]"를 아래 첨자라고합니다.

이 사용은 "오늘"인 경우에만 가능합니다. is a sequence type. Native sequence 유형-목록, 문자열, 튜플 등

오류가 발생했기 때문에 'int'개체는 구독 할 수 없습니다. 이것은 "today"가 시퀀스가 ​​아니라 int 유형 객체임을 의미합니다.

시퀀스를 예상 할 때 '오늘'또는 '어제'가 int 유형 개체 인 이유를 찾아 디버그해야합니다.

[편집 : 명확하게하기 위해]

오류가있을 수 있습니다.

 

참조 페이지 https://stackoverflow.com/questions/4060572

 

 

반응형

댓글