yaml / pyyaml

Canonical source repository for PyYAML
MIT License
2.54k stars 515 forks source link

newline is incorrect #721

Open CalK16 opened 1 year ago

CalK16 commented 1 year ago

When dumping a dictionary, if the value contains \n, with or without spacing around it will cause the output difference. Is it expected? are there any way we can align the behavior?

Python 3.10.8 (main, Nov 29 2022, 21:52:51) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> d = {
...     "case1": "test \n test", 
...     "case2": "test\ntest",
... }
>>> print(yaml.dump(d))
case1: "test \n test"
case2: 'test

  test'

>>> 

I am using

PyYAML==6.0 Python3.10.8