############################################################################### # Date: Sun Aug 19 07:45:46 CDT 2007 # Author/s: John Quigley # Revision: $Id$ ############################################################################### from UserDict import UserDict class HotAttrDict(UserDict): def __init__(self, d): UserDict.__init__(self, d) def __getattr__(self, a): if not self.__dict__.has_key(a): return UserDict.__getitem__(self, a) def test_dict(): d = {'hello':'world', 'how':'are', 'you':'today'} print "Original dict: " + repr(d) h = HotAttrDict(d) print "HotAttr dict: " + repr(h) print "HotAttr data members:" for k,v in h.items(): print k + ':' + v print "Hot attribute h.hello: " + h.hello print "Hot attribute h.how: " + h.how print "Hot attribute h.you: " + h.you def run_tests(test): print "Running test: %(test)s" % locals() globals()['test_%(test)s' % locals()]() if __name__ == '__main__': import sys sys.exit(run_tests(sys.argv[1])) # EOF