Мне было интересно, можете ли вы добавить атрибут в словарь Python.
class myclass():
def __init__():
self.mydict = {} #initialize a regular dict
self.mydict.newattribute = "A description of what this dictionary will hold"
>>>AttributeError: 'dict' object has no attribute 'newattribute'
setattr(self.mydict,"attribute","A description of what this dictionary will hold"
>>>AttributeError: 'dict' object has no attribute 'newattribute'
Есть ли способ быстро добавить мой атрибут описания без необходимости копировать класс dict и перегружать конструктор. Я думал, что это будет просто, но, похоже, я ошибался.
Спасибо, Дж