I've been scouring stackoverflow looking for a way to dump a folded scalar in YAML format using Python. A common answer is from user Anthon who suggests using his ruamel Python library. I took the advice but I cannot figure out how to dump a long Python string value in folded style.
In Anthon's answer's he/she often uses a hard-coded string with the folded style representer ">" to illustrate his point like so:
yaml_str = """\
long: >
Line1
Line2
Line3
"""
data = yaml.load(yaml_str, Loader=yaml.RoundTripLoader)
print(yaml.dump(data, Dumper=yaml.RoundTripDumper))
I'm not sure how to translate that example into my own code where the string value I'd like to dump comes not from a hard-coded value with the folded representer already in it, but from a Django request (well it could come from anywhere really, the point is, I'm not constructing the string in my code manually with ">").
Am I really meant to do something like:
stringToDumpFolded = "ljasdfl\n\nksajdf\r\n;lak'''sjf"
data = "Key: > \n" + stringToDumpFolded
ruamel.yaml.dump(data, f, Dumper=yaml.RoundTripDumper))
Otherwise, given a long unicode string variable, how do I use ruamel to dump it to a file?