The goal is to create a mock class which behaves like a db resultset.
So for example, if a database query returns, using a dict expression, {\'ab\':100, \'cd\'
The best way to achieve is by defining __slots__. That way your instances can't have new attributes.
ks = ['ab', 'cd']
vs = [12, 34]
class C(dict):
__slots__ = []
def __init__(self, ks, vs): self.update(zip(ks, vs))
def __getattr__(self, key): return self[key]
if __name__ == "__main__":
c = C(ks, vs)
print c.ab
That prints 12
c.ab = 33
That gives: AttributeError: 'C' object has no attribute 'ab'