有没有办法在 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())")