我最近在Python中注意到,如果我创建一个dict子类,我可以添加属性,但是这不是dict实例的情况。即:
class aDict(dict):
pass
myDict = aDict({"name" : "A"})
myDict.color = "red"
print(myDict.color) #"red"
myOtherDict = dict({"name" : "B"})
myOtherDict.color = "green" #"AttributeError: 'dict' object has no attribute color"