2013-09-21 13 views
9

Ricevo il seguente errore nel mio codice. Sto tentando di fare un risolutore labirinto e sto ottenendo un errore che dice:TypeError: l'oggetto 'module' non può essere richiamato per l'oggetto python

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

Sto tentando di creare un oggetto chiamato mazem ma a quanto pare che sto facendo qualcosa di sbagliato.

ho scritto queste righe in 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) 

Ecco il mio file maze.py che contiene la classe labirinto:

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

Che cosa è che sto facendo male?

risposta

38

Dovrebbe essere maze.maze() anziché maze().

Oppure è possibile modificare l'istruzione import in from maze import maze.

+0

Grazie! Il primo labirinto fa riferimento al file e il secondo fa riferimento alla classe? – user2604504

+1

@ user2604504 Sì. Ma tecnicamente sta facendo riferimento al 'module' (che è stato costruito con il contenuto del file), non al' file'. –

0

Il problema è l'istruzione di importazione, è possibile importare solo un modulo di classe non. 'labirinto di importazione' è sbagliato, piuttosto utilizzare 'da labirinto di importazione labirinto'

Problemi correlati