Preserve new lines in YAML

后端 未结 2 1288
名媛妹妹
名媛妹妹 2021-01-07 18:45

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 o         


        
相关标签:
2条回答
  • 2021-01-07 19:25

    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
    
    0 讨论(0)
  • 2021-01-07 19:40

    If the extra newline that NullUserException's solutions is adding is a problem you should be using:

    Data: |-
          Some data, here and a special character like ':'
          Another line of data on a separate line
    
    0 讨论(0)
提交回复
热议问题