Reputation: 53
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"
Upvotes: 3
Views: 1864
Reputation: 76902
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.
Upvotes: 4