How do you control how the order in which PyYaml outputs key/value pairs when serializing a Python dictionary?
I\'m using Yaml as a simple serialization format in a
The last time I checked, Python's dictionaries weren't ordered. If you really want them to be, I strongly recommend using a list of key/value pairs.
[
('key', 'value'),
('key2', 'value2')
]
Alternatively, define a list with the keys and put them in the right order.
keys = ['key1', 'name', 'price', 'key2'];
for key in keys:
print obj[key]