I've got an object with a short string attribute, and a long multi-line string attribute. I want to write the short string as a YAML quoted scalar, and the multi-line string as a literal scalar:
my_obj.short = "Hello"
my_obj.long = "Line1
Line2
Line3"
I'd like the YAML to look like this:
short: "Hello"
long: |
Line1
Line2
Line3
How can I instruct PyYAML to do this? If I call yaml.dump(my_obj)
, it produces a dict-like output:
{long: 'line1
line2
line3
', short: Hello}
(Not sure why long is double-spaced like that...)
Can I dictate to PyYAML how to treat my attributes? I'd like to affect both the order and style.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…