I have a Python program that is parsing a number of YAML files, some containing comments, anchors, references, and merge keys that I'd like preserved when I load the YAML file into my parser. ruamel.yaml
seems to have round-trip preservation of these when I run the following:
with open(yaml_file, "r") as f:
yaml = f.read()
parsed_yaml = ruamel.yaml.load(yaml, ruamel.yaml.RoundTripLoader)
print ruamel.yaml.dump(parsed_yaml,Dumper=ruamel.yaml.RoundTripDumper)
Which prints out the original file yaml_file
as it was presented including comments and merge keys. I'm wondering if I can access these comments and other keys while the YAML is parsed in OrderedDict
form. I need to convert these YAML files to an intermediate type, so being able to both get
and set
comments, merge keys, anchors, and references is a high priority.