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"
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"
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?
If you would like them to be kept as newlines, use the literal style, indicated by a pipe ( | ). If instead you want them to be replaced by spaces, use the folded style, indicated by a right angle bracket ( > ). (To get a newline using the folded style, leave a blank line by putting two newlines in.
YAML also supports writing strings on multiple lines in your YAML, with two different styles: literal and folded. Those are represented by a | (for literal style) or > (for folded style) header line (see examples below), and we will go into their differences soon.
In general the order of keys in a YAML file does not matter. Neither do blank lines. Indentation may be with any number of spaces, as long as it is consistent throughout the file. Web PaaS examples by convention use four-space indentation.
In YAML, strings can be represented in the following several ways: Single-quoted scalars. Double-quoted scalars. Unquoted scalars. Folded scalars.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With