1

I want to read and write to several yaml files without changing the entire format of the file. When I use yaml.load and yaml.dump the format is entirely changed, resulting in many changed lines.

I only want to insert a key into several dictionaries that are missing the key. I also looked into using ruamel.yaml but it does not preserve format according to this answer: https://stackoverflow.com/a/54278583/4044470

Jonathan Allen Grant
  • 3,408
  • 6
  • 30
  • 53
  • Look for a pretty print python library for yaml. – betico Jan 29 '19 at 23:04
  • That answer doesn't say ruamel.yaml does not preserve format. It says it does not completely preserve the original format. And that is not the accepted answer for the question. You can use ruamel.yaml to analyse your indentation, and it will make it consistent over the full YAML document. So if your document is already consistent within itself, there is more than a good chance that round-tripping does keep things as they are. – Anthon Jan 29 '19 at 23:32

0 Answers0