Using @property decorator on dicts
I'm trying to use Python's @property decorator on a dict in a class. The idea is that I want a certain value (call it 'message') to be cleared after it is accessed. But I also want another value (call it 'last_message') to contain the last set message, and keep it until another message is set. In my mind, this code would work: >>> class A(object): ... def __init__(self): ... self._b = {"message": "", ... "last_message": ""} ... @property ... def b(self): ... b = self._b ... self._b["message"] = "" ... return b ... @b.setter ... def b(self, value): ... self._b = value ... self._b["last_message"