Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'module' object is not callable for python object

Tags:

python

I'm getting the following error in my code. I am attempting to make a maze solver and I am getting an error that says:

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

I am attempting to create a maze object called m but apparently I'm doing something wrong.

I wrote these lines 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)

Here is my maze.py file which contains the maze class:

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

What is it that I am doing wrong?

like image 535
user2604504 Avatar asked Sep 21 '13 04:09

user2604504


People also ask

How do I fix TypeError module object is not callable in Python?

How to fix typeerror: 'module' object is not callable? To fix this error, we need to change the import statement in “mycode.py” file and specify a specific function in our import statement.

Why is my DataFrame object not callable?

This error usually occurs when you attempt to perform some calculation on a variable in a pandas DataFrame by using round () brackets instead of square [ ] brackets.

Why is my class not callable Python?

This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .


1 Answers

It should be maze.maze() instead of maze().

Or you could change your import statement to from maze import maze.

like image 83
Bleeding Fingers Avatar answered Oct 14 '22 00:10

Bleeding Fingers