I'd like to get the comment strings from a YAML file I loaded using ruamel.yaml
. The project documentation lacks an API reference and I can't find a relevant example. What's the right way to access the comments?
import ruamel.yaml
yaml = """\
%YAML 1.2
---
# C1
a: # C2
# C3
# C4
b: 1 # C5
c: # A comment here will not be parsed properly by ruamel.yaml v0.11.14
- abc # C6
- xyz # C7
# C8
# C9
"""
loaded = ruamel.yaml.round_trip_load(yaml)
# Now what?
The library author comments on this in an issue on BitBucket (May 9, 2016):
Through some experimentation I determined the following works for the example code provided in the question above: