2013-05-22 5 views
2

이 메서드를 작동 시키려고하지만이를 수행하지 않습니다.형식 오류 : 튜플 인덱스는 튜플이 아닌 정수 여야합니다.

관련 코드 : 튜플 지표가 될 정수,

는 내가 어디를 수정해야 튜플 안 :

for (i, t) in enumerate(transitions[location]): 
    print i+1, t[0] 
actionChoice=int(raw_input("> ")) 
console.clear() 
transitions=transitions[location][actionChoice-1] 

나는 유형 오류 얻을? 무슨 뜻이에요?

답변

5

location은 튜플입니다.

수정 :

>>> tup=(1,2) 
>>> tup[0] 
1 

또한 enumerate 당신이 여기

+0

내가 5 인 것처럼 설명합니다. 나는 Python을 처음 사용한다. – user2407771

+0

@location은 변수'location'를 검사합니다. 정수로 잘못 입력했지만 실제로는 튜플입니다. 아마도 위치 [0]을 사용하거나 비슷한 것을 의미 할 수도 있습니다. – jamylak

+0

아마도 열거 형 (전환)이 될 것입니다 – Patashu

0

i+1를 작성 피하기 위해 enumerate(x, start=1)을 사용할 수 있도록 start 매개 변수를 허용하는 데모입니다 있습니다 transitions[location]

:이 줄은 오류가 발생합니다 올바르지 않음 :

>>> tup[(0,0)] 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: tuple indices must be integers, not tuple 
>>> tup[1,] 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: tuple indices must be integers, not tuple 

위치는 튜플 (정수가 아님) 일 가능성이 큽니다.

관련 문제