Archive for June, 2009

Python – pretty dictionary access for objects

Sunday, June 28th, 2009

Instead of hash like access i.e. val = hash['key']

You can achieve a prettier val = obj.key :

class Obj:
..def add(self, k, v):
....self.__dict__[k] = v

o = Obj()
o.add(key, val)