为什么不在 boolens 字典中理解为函数调用?
Why not in a dictionary of boolens is understood as a function call?
我有以下
class ShowOptions(Enum):
MenuBBoxes =0
Show_A = 1
Show_B =2
Show_C =3
Show_D =4
isShown = { ShowOptions.MenuBBoxes: True,
ShowOptions.Show_A: True,
ShowOptions.Show_B:True,
ShowOptions.Show_C:True,
ShowOptions.Show_D:True}
我正在尝试切换布尔值,例如
isShown[(h-1)]= not isShown[(h-1)]
但这给了我错误
TypeError: 'NoneType' object is not callable
不明白为什么not不能用。
注意:如果我这样做
isShown[(h-1)]= not (1==0)
没有出现问题
您 dict
的键是 Enum
而不是 int
。您不能互换使用它们。如果您想从 dict
访问某些内容,您需要使用 Enum
定义,例如:
from enum import Enum
class ShowOptions(Enum):
MenuBBoxes = 0
Show_A = 1
Show_B = 2
Show_C = 3
Show_D = 4
isShown = {ShowOptions.MenuBBoxes: True,
ShowOptions.Show_A: True,
ShowOptions.Show_B: True,
ShowOptions.Show_C: True,
ShowOptions.Show_D: True}
isShown[ShowOptions.MenuBBoxes] = not isShown[ShowOptions.MenuBBoxes]
print(isShown)
如果你想使用它们的值,你必须像这样调用你的枚举类型:
isShown[ShowOptions(0)] = not isShown[ShowOptions(0)]
print(isShown)
我想你正在寻找类似的东西:
isShown[ShowOptions(h - 1)] = not isShown[ShowOptions(h - 1)]
我有以下
class ShowOptions(Enum):
MenuBBoxes =0
Show_A = 1
Show_B =2
Show_C =3
Show_D =4
isShown = { ShowOptions.MenuBBoxes: True,
ShowOptions.Show_A: True,
ShowOptions.Show_B:True,
ShowOptions.Show_C:True,
ShowOptions.Show_D:True}
我正在尝试切换布尔值,例如
isShown[(h-1)]= not isShown[(h-1)]
但这给了我错误
TypeError: 'NoneType' object is not callable
不明白为什么not不能用。 注意:如果我这样做
isShown[(h-1)]= not (1==0)
没有出现问题
您 dict
的键是 Enum
而不是 int
。您不能互换使用它们。如果您想从 dict
访问某些内容,您需要使用 Enum
定义,例如:
from enum import Enum
class ShowOptions(Enum):
MenuBBoxes = 0
Show_A = 1
Show_B = 2
Show_C = 3
Show_D = 4
isShown = {ShowOptions.MenuBBoxes: True,
ShowOptions.Show_A: True,
ShowOptions.Show_B: True,
ShowOptions.Show_C: True,
ShowOptions.Show_D: True}
isShown[ShowOptions.MenuBBoxes] = not isShown[ShowOptions.MenuBBoxes]
print(isShown)
如果你想使用它们的值,你必须像这样调用你的枚举类型:
isShown[ShowOptions(0)] = not isShown[ShowOptions(0)]
print(isShown)
我想你正在寻找类似的东西:
isShown[ShowOptions(h - 1)] = not isShown[ShowOptions(h - 1)]