From: Steve H. <sh...@zi...> - 2002-09-08 17:04:36
|
----- Original Message ----- From: "Mike Orr" <ir...@ms...> > Many applications will have a preferred key order they impose on the > data, no matter which order it comes in from the .yml file. Others > won't give a rip what order the elements are in. And for those apps > that really, really want to know what order the keys were in in the .yml > file, we can provide "something else" that tells that. Since a > dictionary can be represented as a list of pairs, why not have an entry > method that parses them that way? Parse everything else normally but > convert dictionaries to lists of pairs. Then the user gets the key > order and can make their own dictionary. That would also allow them to > do advanced processing of duplicate keys. > I envision something this. class OrderedHash: def set(key, value): # puts new key/value pair into an ordered hash class HashFactory: def new(): return OrderedHash() parser = yaml.Parser() parser.setHashFactory(HashFactory) for doc in parser.load(): # do whatever Cheers, Steve |