Controlling Yaml Serialization Order in Python

后端 未结 4 1066
渐次进展
渐次进展 2020-12-15 08:42

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

4条回答
  •  醉酒成梦
    2020-12-15 08:56

    New Solution (as of 2020 and PyYAML 5.1)

    You can dump a dictionary in its current order by simply using

    yaml.dump(data, default_flow_style=False, sort_keys=False)
    

提交回复
热议问题