Let me propose my DictObj
class, which I've been using for issues like this:
class DictObj(dict):
"""
a dictionary like class that allows attribute-like access to its keys
d = DictObj(a=2, b=7)
d['a'] --> 2
d.a --> 2
"""
def __getattr__(self, name):
return self.__getitem__(name)
def __setattr__(self, name, value):
if name in self:
self.__setitem__(name, value)
else:
super(DictObj, self).__setattr__(name, value)
def __add__(self, other):
res = DictObj(self)
res.update(other)
return res
Items are stored in the dictionary, but can alternatively be accessed as attributes of the object.
You can extend this easily with more magic methods to suit your needs.