Skip to content
Advertisement

Difference of Double Quotes and Vertical bar in yaml

I’m writing a Python script that creates a YAML file according to DataFrame and I came across this:

JavaScript

vs

JavaScript

Are they technically the same or am I missing something? If they are not the same, how do I make the second version like the first that uses a vertical bar.

Advertisement

Answer

They are technically not the same, but they are similar, as you can see by loading them:

JavaScript

which gives:

JavaScript

The double quoted style can represent any string using backslash escapes, but is not always very readable.

If you have a string with just linebreaks, you can often use the first form, called a literal style scalar.

You can create individual literal style scalars using the following (of course you don’t have to start from loaded data, you can just as well create that in YAML):

JavaScript

which gives:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement