![](/img/trans.png)
[英]Type error ' list indices must be integers or slices, not tuple' (line 6)
[英]Type error: Tuple indices must be integers, not tuple
我正在尝试使这种方法起作用,但不会。
相关代码:
for (i, t) in enumerate(transitions[location]):
print i+1, t[0]
actionChoice=int(raw_input("> "))
console.clear()
transitions=transitions[location][actionChoice-1]
我收到类型错误:元组索引必须是整数,而不是元组
我应该在哪里修理? 这是什么意思?
location
是一个元组。 此行导致错误: transitions[location]
还要注意, enumerate
接受start
参数,因此您可以使用enumerate(x, start=1)
避免写入i+1
这是一个演示:
正确:
>>> tup=(1,2)
>>> tup[0]
1
不正确:
>>> 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
位置很可能是一个元组-不是整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.