mkPyVS wrote: > This isn't so optimal but I think accomplishes what you desire to some > extent... I *think* there is some hidden gem in inheriting from dict > or an mapping type that is cleaner than what I've shown below though. > > class dum_struct: > def __init__(self,keyList,valList): > self.__orderedKeys = keyList > self.__orderedValList = valList > def __getattr__(self,name): > return self.__orderedValList[self.__orderedKeys.index(name)] > > > keys = ['foo','baz'] > vals = ['bar','bal'] > > m = dum_struct(keys,vals) > > print m.foo >
Let's add: __getitem__(self, key): return self.__orderedValList[key] in order to have: m.foo == m[0] RB -- http://mail.python.org/mailman/listinfo/python-list