【发布时间】:2012-01-28 15:53:15
【问题描述】:
我正在寻找一种干净、简单的方法来更新继承自基类的类级别字典。例如:
class Foo(object):
adict = {'a' : 1}
class Bar(Foo):
adict.update({'b' : 2}) # this errors out since it can't find adict
这样:
Foo.adict == {'a' : 1}
Bar.adict == {'a' : 1, 'b' : 2}
我不想在这里使用实例,如果可能的话也不要使用类方法。
【问题讨论】:
标签: class inheritance dictionary python-3.x