I can't seem to figure out how I can add a blank line between data using Ruamel.yaml.
Suppose I have data:
---
a: 1
b: 2
I need to add to this so that I will have:
---
a: 1
b: 2
c: 3
I understand that the blank line is implemented as a CommentToken:
Comment(comment=None,
items={'data': [None, None, CommentToken(value=u'\n\n'), None], 'b': [None, None, CommentToken(value=u'\n\n'), None]})
What I don't know is how to manipulate that structure.
That
Comment
object is not from the input that you give, asdata
is not a key in your mapping, that should bea
:gives:
comparing the above comments should give you an idea of what to try:
which gives:
The CommentToken
ct
can also be constructed from scratch:as is, e.g. done in
ruamel.yaml.comments.CommentedBase.yaml_set_start_comment()
.The
0
parameter toCommentMark()
is how far the comment is indented, which is not important in case of empty lines, but still needs to be provided.