You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(This is related to issue #240). Dumping a multiline string adds newlines, so the dumped data is different from the actual data. Consider the following:
Input.yaml
---
- |
Hi!
Second Line
Another Line
My program:
import yaml
with open("input.yaml") as db:
data = yaml.load(db)
print(yaml.dump(data, default_flow_style=False))
The output:
- 'Hi!
Second Line
Another Line
'
This is clearly incorrect: this simple program changes my data even though I am simply reading and dumping it
The text was updated successfully, but these errors were encountered:
It's not a bug. Both strings are actually the same. Represented in doublequotes: "Hi!\nSecond Line\nAnother Line\n"
In single quotes, several lines get folded, so newlines vanish. Only if you have empty lines in between, the newline does not get folded.
I agree that in this case it would be nicer to output with the same block scalar style |, but figuring out which string style to use when dumping is not trivial.
How about capturing some metadata about string at load time, eg if there is "|" take note of it for when it gets dumped. On a new element, you should be able to add that metadata.
@schollii sure, that would be possible, and ruamel.yaml does it.
But PyYAML has other issues right now that are more urgent IMHO, like YAML 1.2 support
(This is related to issue #240). Dumping a multiline string adds newlines, so the dumped data is different from the actual data. Consider the following:
Input.yaml
My program:
The output:
This is clearly incorrect: this simple program changes my data even though I am simply reading and dumping it
The text was updated successfully, but these errors were encountered: