Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape hash sign in Yaml multiline text

Tags:

yaml

Is it possible to escape a hash sign (#) from a multiline text?

...
-
    my_story: |
        Line 1
        Line 2
        # Hash line

What I was hoping to get is:

array {
    'my_story' => 'Line 1
Line 2
# Hash line'
}

If I wrap the hash line with quotes I get them in the text:

'Line 1
Line 2
"# Hash line"'

Any ideas..?

like image 271
tamir Avatar asked Dec 12 '13 16:12

tamir


1 Answers

What you wrote is perfectly fine and '#' should be correctly processed. The following code works just fine in Python 3 (pyyaml)

data="""
-
    my_story: |
        Line 1
        Line 2
        # Hash line
"""

import yaml

deserializedData = yaml.load ( data )

print ( deserializedData[0]['my_story'] )

The above line prints

Line 1
Line 2
# Hash line
like image 124
ganeshsamant Avatar answered Sep 21 '22 15:09

ganeshsamant