You can implement a custom dict
wrapper (either a subclass of dict
or something that contains a dict
) and implement __getattr__
(or __getattribute__
) to return data from the dict
.
class DictObject(object):
def __init__(self, data):
self.mydict = data
def __getattr__(self, attr):
if attr in self.mydict: return self.mydict[attr]
return super(self, DictObject).__getattr__(attr)
solved Access dict via dict.key