Following from this question, I’d like to set a preferred quoting style to be double-quotes, yet allow strings that can be represented as plain (no quotes) to be shown in plain. This is because I’m trying to fit a “house style” even though single quotes are valid yaml and maybe even preferable for some. Here’s a simple test-case:
import sys
from ruamel.yaml import YAML
data = {
'a': 'non-plain : scalar',
'b': 'also nontplain',
'c': 'plain',
}
def test():
yaml = YAML()
yaml.default_flow_style = False
# yaml.default_style='"'
yaml.dump(data, sys.stdout)
test()
This outputs (correctly) with variable quoting:
a: 'non-plain : scalar'
b: "also nontplain"
c: plain
Uncomment the default_style
line, everything gets double quotes, thus:
"a": "non-plain : scalar"
"b": "also nontplain"
"c": "plain"
I’d like an option to indicate a preferred quote style to be applied only when needed, else plain non-quoted style:
a: "non-plain : scalar"
b: "also nontplain"
c: plain