调用 list.index(a) 会导致属性调用,而不是方法?

Calling list.index(a) results in attribute call, not method?

我一直在尝试创建一个脚本,将列表放入字典中,然后编辑它们以创建类似网格的东西。我试图使一个变量等效于列表中值的索引,但错误表明数据中没有这样的属性。我正在尝试调用方法,而不是检索属性,但这就是机器认为我想要做的。

我使用的是 Python 3.5.

的 32 位版本

这是脚本。我已经在相关行中添加了评论。

#Map Generation Script
GRID = {
1 : [1,1,1,1,1,1,1,1,1,1],
2 : [1,1,1,1,1,1,1,1,1,1],
3 : [1,1,1,1,1,1,1,1,1,1],
4 : [1,1,1,1,1,1,1,1,1,1],
5 : [1,1,1,1,1,1,1,1,1,1],
6 : [1,1,1,1,1,1,1,1,1,1],
7 : [1,1,1,1,1,1,1,1,1,1],
8 : [1,1,1,1,1,1,1,1,1,1],
9 : [1,1,1,1,1,1,1,1,1,1],
10 : [1,1,1,1,1,1,1,1,1,1]
}

def usepen(x):
Areaedit = GRID[godpenx]
Areaedit[godpeny] = x
GRID[godpenx] = Areaedit

def makeshapeline(tile, length):
for item in GRID:               #I know this isn't indented properly
    for unit in GRID[item]:
        if unit == tile:
            locpenx = GRID.index(item) #offending line
            locpeny = GRID[item].index(tile) 
            anglea = randrange(0,1)
            angleb = randrange(0,1)
            while anglea + angleb == 0:
                anglea = randrange(0,1)
                angleb = randrange(0,1)
            for nump in length:
                locpenx += anglea
                locpeny += angleb
                if locpenx or locpeny > 9:
                    break
                GRID[locpenx[locpeny]] = tile

usepen(0)
makeshapeline(0, randrange(1,8))
for item in GRID:
    print (GRID[item])

确实 locpenx = GRID.index(item) 是违规行:

你需要这样的东西 -

locpenx = GRID[1].index(item) 

locpenx = GRID[2].index(item) 

..等等。