On Feb 20, 12:07 pm, thebjorn <[EMAIL PROTECTED]> wrote: > On Feb 20, 3:32 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote: > > > > > On Feb 20, 2008 8:15 AM, Larry Bates <[EMAIL PROTECTED]> wrote: > > > > Jorge Vargas wrote: > > > > I need a data structure that will let me do: > > > > > - attribute access (or index) > > > > - maintain the order (for iter and print) > > > > - be mutable. > > [...] > > > > Sounds like a good time to learn ElementTree (included in Python 2.5 but > > > available for earlier versions). > > > I am using ET, to fetch the data from the XML, after that I want a > > plain python object. for the rest of the program. > > Ok, you just lost me... Why do you thin ET is not appropriate (*)? It > fits all your requirements, is optimized for representing hierarchical > data (especially xml), it is fast, it is well tested, it has a > community of users, it is included in the standard library, etc., etc. > > ...maybe I didn't grok what you meant by "plain python object"? > > -- bjorn > > (*) I just had a flashback to the movie ET -- the scene when he's in > the closet ;-)
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 -- http://mail.python.org/mailman/listinfo/python-list