我遇到了将字符串连接到变量以在我的程序(pythonista app)中创建方法的问题。它是这样的:
buttons = ''' Scan_View Show_View '''.split()
class OCRApp():
def __init__(self):
pass
def scan_view_action(self, sender):
scanview = ui.load_view('scanview.pyui')
scanview.background_color = 'red'
scanview.present()
def show_view_action(self, sender):
pass
def make_button(self, name, i):
button = ui.Button(title=name)
the_action = name + '_action'
button.action = the_action()
button.center = w / 2, (i * 60) + (button.height * 2)
self.add_subview(button)
return button
当我在变量the_action
上创建一个字符串并在button.action
上调用它时出现错误:
TypeError: "str" object is not callable
我该如何正确地做到这一点?