TypeError: 'bool' object is not callable
Question:
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
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.
Actually you can fix it with following steps –
- Do
cls.__dict__
- This will give you dictionary format output which will contain
{'isFilled':True}
or {'isFilled':False}
depending upon what you have set.
- Delete this entry –
del cls.__dict__['isFilled']
- You will be able to call the method now.
In this case, we delete the entry which overrides the method as mentioned by 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
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
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.
Actually you can fix it with following steps –
- Do
cls.__dict__
- This will give you dictionary format output which will contain
{'isFilled':True}
or{'isFilled':False}
depending upon what you have set. - Delete this entry –
del cls.__dict__['isFilled']
- You will be able to call the method now.
In this case, we delete the entry which overrides the method as mentioned by 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