Look at this code, under Python 2.7:
>>> import yaml
>>> yaml.load('string: 01')
{'string': 1}
>>> :(
Is it possible to obtain the string 01
without modifying the yaml file? I didn't find anything in the docs.
For most scalars you don't need any quotes at all, but if you need to define some piece of data which contains characters that could be mistaken with YAML syntax you need to quote it in either double " or single ' quotes for the YAML file to stay valid.
Quotes are required when the string contains special or reserved characters. The double-quoted style provides a way to express arbitrary strings, by using \ to escape characters and sequences. For instance, it is very useful when you need to embed a \n or a Unicode character in a string.
The default, clip, puts a single newline at the end of the string. To remove all newlines, strip them by putting a minus sign ( - ) after the style indicator.
Try:
>> import yaml
>> yaml.load('string: 01', Loader=yaml.loader.BaseLoader)
{u'string': u'01'}
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