I want to write a custom class that behaves like dict - so, I am inheriting from dict.
dict
My question, though, is: Do I need to create a priva
This is my best solution. I used this many times.
class DictLikeClass: ... def __getitem__(self, key): return getattr(self, key) def __setitem__(self, key, value): setattr(self, key, value) ...
You can use like:
>>> d = DictLikeClass() >>> d["key"] = "value" >>> print(d["key"])