Python TypeError: 'NoneType' object is not callable
程序员文章站
2024-02-12 20:29:22
...
I am mere a beginner of Python. I am getting the following error and suspect that it has something to do with the dictionary I've used as switch case (since python does not provide switch ). Following is my code:
class Arithmetic:
a,b,choice = 0,0,0
def __init__(self):
print "\n\n"
for num in range(30):
print "*",
print "\n"
print "Welcome to CLC (Command Line Calculator)"
print "\n"
for num in range(30):
print "*",
print "\n"
def menu(self):
print "1. Add"
print "2. Substract"
print "3. Multiply"
print "4. Divide"
print "5. Modulo"
print "6. Exit \n\n"
self.choice = raw_input("Enter Your Choice: ")
if self.choice == '0':
exit("Thank you for using the program")
selector = {
"1" : self.add(),
"2" : self.substract(),
"3" : self.multiply(),
"4" : self.divide(),
"5" : self.modulo()
}
selector[self.choice]()
def add(self):
print "Add called"
def substract(self):
print "Substract called"
def multiply(self):
print "Multiply called"
def divide(self):
print "Divide called"
def modulo(self):
print "Modulo called"
def main(self):
while self.choice != '6':
self.menu()
a = Arithmetic()
a.menu()
The Error is:
When you do
self.add()
you are calling the method (you will get a result). If you want to specify the method, delete the ()
:
selector = {
"1" : self.add,
"2" : self.substract,
"3" : self.multiply,
"4" : self.divide,
"5" : self.modulo
}
Traceback (most recent call last):
File "arithmetics.py", line 75, in <module>
a.menu()
File "arithmetics.py", line 43, in menu
selector[self.choice]()
TypeError: 'NoneType' object is not callable
下一篇: Oracle数据库备份技巧
推荐阅读
-
Python TypeError: 'NoneType' object is not callable
-
TypeError: 'NoneType' object is not callable
-
装饰器 TypeError: 'NoneType' object is not callable
-
解决:TypeError: 'list' object is not callable
-
报错:TypeError: 'NoneType' object is not callable问题解决
-
Debug3:使用DataFrame时报错TypeError: 'NoneType' object is not callable
-
TypeError: 'NoneType' object is not callable--python报错
-
U-Net运行报错merge6 = merge([drop4,up6], mode = 'concat'...) TypeError: 'module' object is not callable
-
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
-
python3_opencv_直线检测_HoughLinesP_ 'NoneType' object is not subscriptable