小编Art*_*hur的帖子

Python YAML保留换行符而不添加额外的换行符

我对这个问题有类似的问题,我需要在YAML映射值字符串中插入换行符,而不想插入\n自己.答案建议使用:

Data: |
      Some data, here and a special character like ':'
      Another line of data on a separate line
Run Code Online (Sandbox Code Playgroud)

代替

Data: "Some data, here and a special character like ':'\n
      Another line of data on a separate line"
Run Code Online (Sandbox Code Playgroud)

这也增加了一个新行,即是不可接受的.

我尝试使用Data: >但显示出完全不同的结果.我在读完yaml文件后一直在剥离最终换行符,当然这样可行,但这并不优雅.有没有更好的方法来保留换行符而不在末尾添加额外的换行符?

我正在使用python 2.7 fwiw

python yaml

6
推荐指数
1
解决办法
2328
查看次数

标签 统计

python ×1

yaml ×1