In the https://pypi.python.org/pypi/ruamel.yaml change log there is an entry: 0.11.12 (2016-07-06):
- added support for roundtrip of single/double quoted scalars using:
ruamel.yaml.round_trip_load(stream, preserve_quotes=True)
Using ruamel I can convert:
skip: Skip
show: 'Show'
remove: "Remove"
"info_on": "ON"
to:
skip: Skip
show: Show
remove: Remove
info_on: ON
Is there an option in ruamel to add rather than preserve quotes resulting in:
"skip": "Skip"
"show": "Show"
"remove": "Remove"
"info_on": "ON"
You can do that with the dump() option default_style='"':
import sys
import ruamel.yaml
yaml_str = """\
skip: Skip
show: 'Show'
remove: "Remove"
"info_on": "ON"
"""
data = ruamel.yaml.round_trip_load(yaml_str)
ruamel.yaml.round_trip_dump(data, sys.stdout, default_style='"')
in the same way as you can do for the old PyYAML from which ruamel.yaml is derived.
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