在 YAML 中保留新行 [英] Preserve new lines in YAML
本文介绍了在 YAML 中保留新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何格式化这样的 YAML 文档,以便 PyYAML 可以正确解析它?
How do I format a YAML document like this so that PyYAML can parse it properly?
Data: Some data, here and a special character like ':'
Another line of data on a separate line
我知道 ':' 字符很特别,所以我必须像这样用引号将整个内容括起来:
I know that the ':' character is special so I have to surround the whole thing in quotations like so:
Data: "Some data, here and a special character like ':'
Another line of data on a separate line"
为了添加新行,我必须添加'\n':
And in order to add a new line, I have to add '\n':
Data: "Some data, here and a special character like ':'\n
Another line of data on a separate line"
有没有办法格式化 YAML 文档,这样我就不必添加\n
"来换行?
Is there anyway to format the YAML document so I don't have to add the '\n
's in order to have a new line?
推荐答案
对于多行标量,您可以使用块.字符 |
表示块的开始.使用:
For multi-line scalars, you can use blocks. The character |
denotes the start of a block. Use:
Data: |
Some data, here and a special character like ':'
Another line of data on a separate line
这篇关于在 YAML 中保留新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文