Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'bool' object is not callable

Tags:

python

I am brand new to python. I got a error

while not cls.isFilled(row,col,myMap):
TypeError: 'bool' object is not callable

Would you please instruct how to solve this issue? The first "if" check is fine, but "while not" has this error.

def main(cls, args):
        ...
        if cls.isFilled(row,col,myMap):
            numCycles = 0

        while not cls.isFilled(row,col,myMap):
            numCycles += 1


def isFilled(cls,row,col,myMap):
        cls.isFilled = True
        ## for-while
        i = 0
        while i < row:
            ## for-while
            j = 0
            while j < col:
                if not myMap[i][j].getIsActive():
                    cls.isFilled = False
                j += 1
            i += 1
        return cls.isFilled
like image 517
Mike Avatar asked Sep 27 '12 04:09

Mike


People also ask

How do I fix bool is not callable?

The Python "TypeError: 'bool' object is not callable" occurs when we try to call a boolean value ( True or False ) as a function. To solve the error, correct the assignment and resolve any clashes between function and variable names.

Why is the bool not callable in Python?

Bool type objects do not respond to a function call because they are not functions. If you try to call a Bool type object if it were a function, the Python interpreter will raise the TypeError: 'bool' object is not callable.

How do I fix this object is not callable?

The Python "TypeError: object is not callable" occurs when we try to call a not-callable object (e.g. a list or dict) as a function using parenthesis () . To solve the error, make sure to use square brackets when accessing a list at index or a dictionary's key, e.g. my_list[0] .

How do I fix TypeError int object is not callable?

But in Python, this would lead to the Typeerror: int object is not callable error. To fix this error, you need to let Python know you want to multiply the number outside the parentheses with the sum of the numbers inside the parentheses. Python allows you to specify any arithmetic sign before the opening parenthesis.


2 Answers

You do cls.isFilled = True. That overwrites the method called isFilled and replaces it with the value True. That method is now gone and you can't call it anymore. So when you try to call it again you get an error, since it's not there anymore.

The solution is use a different name for the variable than you do for the method.

like image 130
BrenBarn Avatar answered Oct 11 '22 04:10

BrenBarn


def isFilled(cls,row,col,myMap):
        cls.isFilled = True

the error is in here

you have a function/method named isFilled() and a attribute of cls instance named isFilled, too. Python thinks they are the same

def isFilllllllllllllllled(cls,row,col,myMap):
        cls.isFilled = True

you can change, for example, as above and it will work

like image 1
lam vu Nguyen Avatar answered Oct 11 '22 04:10

lam vu Nguyen