我的代码中出现以下错误。我正在尝试制作迷宫求解器,但收到一条错误消息:
Traceback (most recent call last):
File "./parseMaze.py", line 29, in <module>
m = maze()
TypeError: 'module' object is not callable
我正在尝试创建一个maze
名为m
但显然我做错了什么的对象。
我把这些行写在parseMaze.py
#!/user/bin/env python
import sys
import cell
import maze
import array
# open file and parse characters
with open(sys.argv[-1]) as f:
# local variables
x = 0 # x length
y = 0 # y length
char = [] # array to hold the character through maze
iCell = []# not sure if I need
# go through file
while True:
c = f.read(1)
if not c:
break
char.append(c)
if c == '\n':
y += 1
if c != '\n':
x += 1
print y
x = x/y
print x
m = maze()
m.setDim(x,y)
for i in range (len(char)):
if char(i) == ' ':
m.addCell(i, 0)
elif char(i) == '%':
m.addCell(i, 1)
elif char(i) == 'P':
m.addCell(i, 2)
elif char(i) == '.':
m.addCell(i, 3)
else:
print "do newline"
print str(m.cells)
这是我的maze.py
文件,其中包含迷宫类:
#! /user/bin/env python
class maze:
w = 0
h = 0
size = 0
cells =[]
# width and height variables of the maze
def _init_(self):
w = 0
h = 0
size = 0
cells =[]
# set dimensions of maze
def _init_(self, width, height):
self.w = width
self.w = height
self.size = width*height
# find index based off row major order
def findRowMajor(self, x, y):
return (y*w)+x
# add a cell to the maze
def addCell(self, index, state):
cells.append(cell(index, state))
我做错了什么?