我正在尝试设计一个在库中具有多个分配属性的父类。
class CC():
Features = {"1" : "", "2" : ""}
class F(CC):
Features["1"] = { key : value }
当我尝试覆盖该类的子字典中的元素(使用子字典)时,它给了我:
Traceback (most recent call last):
File "C:\Python27\Rough\Starting UP\AttributeInput.py", line 7, in <module>
PersonClass = Fighter()
File "C:\Python27\Rough\Starting UP\CharClass.py", line 45, in __init__
classFeatures["1"] = {"Bonus Feat" : "Select a free feat from Fighter List"}
NameError: global name 'classFeatures' is not defined
在全局中声明字典似乎是一个糟糕的主意,那么如何在不将“功能”的键分解为它们自己的特定值的情况下覆盖特定元素呢?
编辑如下评论