有没有办法在python中使用变量字符串访问变量?例如,我想要比使用eval
更简洁的方法:
def toggleListButtons (self):
buttons = ["flip", "remove", "removeAll", "delete", "deleteAll", "loadDirectory"]
for button in buttons:
eval("self." + button + "Button.setEnabled(!self." + button + "Button.isEnabled())")