我正在尝试在显示为 view(),add(),delete 和 exit_program 的元组中调用函数。但是,每当我运行代码时,控制台都会返回:
TypeError: view() missing 1 required positional argument: 'self'
我还尝试在功能之前添加 self 或 Menu ,但无济于事。反正有解决办法吗?
代码如下:
from collections import namedtuple
class Menu(object):
def view(self):
pass
def add(self):
pass
def delete(self):
pass
def exit_program(self):
exit()
Option = namedtuple("Option", "label", "function")
_separator = "=" * 25
_options = {1: Option('View goals', view()), 2: Option('Add new goal', add()),
3: Option('Delete existing goal', delete()), 4: Option('Exit program', exit_program())}