2013-09-21 1 views
9

내 코드에서 다음 오류가 발생합니다. 나는 미로 해석을 시도하고 나는 말한다 오류가 점점 오전 : 나는 m라는 maze 개체를 만들려고하고 있어요하지만 분명히 내가 뭔가 잘못하고 있어요TypeError : 'module'객체가 파이썬 객체에 대해 호출 할 수 없습니다.

Traceback (most recent call last): 
    File "./parseMaze.py", line 29, in <module> 
    m = maze() 
TypeError: 'module' object is not callable 

.

내가 여기 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)) 

는 내가 잘못하고있는 중이 야 그 무엇입니까?

답변

38

maze() 대신 maze.maze()이어야합니다.

또는 import 문을 from maze import maze으로 변경할 수 있습니다.

+0

감사합니다! 첫 번째 미로가 파일을 참조하고 두 번째 미로가 클래스를 참조합니까? – user2604504

+1

@ user2604504 예. 그러나 기술적으로는'file'이 아닌'module' (파일 내용으로 생성 된)을 참조하고 있습니다. –

0

문제는 import 문입니다. 모듈이 아닌 클래스 만 가져올 수 있습니다. 'import maze'가 잘못 사용되었습니다. 'from maze import maze'

관련 문제