On Thu, Feb 21, 2008 at 2:52 AM, Robert Bossy <[EMAIL PROTECTED]> wrote:
> 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]
>
this seems like a good start, maybe replacing the internal structures
with a list and a dict will get better  performance, I'll work in it a
little, if I get something productive I'll probably post a recipe
>
>  in order to have: m.foo == m[0]
>
>  RB
>
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to