2013-09-21 15 views
9

私のコードで次のエラーが発生します。私は、迷路のソルバーを作るしようとしていると私はというエラーを取得しています:私はmと呼ばれるmazeオブジェクトを作成しようとしていますが、どうやら私が何か間違ったことをやっているTypeError: 'モジュール'オブジェクトがPythonオブジェクトに対して呼び出せません

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

#! /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)) 

それは私が間違っているのことは何ですか:

私はここで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ファイルのですか?

答えて

38

maze()ではなく、maze.maze()である必要があります。

importの文をfrom maze import mazeに変更することもできます。

+0

ありがとう!最初の迷路はファイルを参照し、2番目の迷路はクラスを参照していますか? – user2604504

+1

@ user2604504はい。しかし、技術的には 'file'ではなく、' module'(ファイルの内容で構築されたもの)を参照しています。 –

0

問題はインポートステートメントです。モジュールではなくクラスのみをインポートできます。 'import maze'が間違っています 'from maze import maze'

関連する問題