【发布时间】:2012-05-28 18:03:03
【问题描述】:
我有这个代码:
level = {0, 0, 0,
0, 1, 0,
0, 0, 0}
class player:
def getPlayerLoc(self, level):
for i in level:
if level[level.index(i)] == 1:
print "Player location = " + str(i)
p1 = player()
p1.getPlayerLoc(level)
当我运行它时,它会说:
Traceback (most recent call last):
File "gamy.py", line 13, in <module>
p1.getPlayerLoc(level)
File "gamy.py", line 8, in getPlayerLoc
if level[level.index(i)] == 1:
AttributeError: 'set' object has no attribute 'index'
看起来它正在将我的数组转换为一个集合对象。为什么会这样,我该如何解决?
【问题讨论】:
-
呃,那是一个集合对象。您的意思是使用列表吗?
标签: python arrays compiler-errors set