I have python dict:
t1 = [{'system': 'android',
'nice': False,
'pass': [{'success': ['a', 'b', 'c']}],
'warning': [{'pass': ['a', 'b', 'c']}],
'number': 1}]
I need to get YAML like this, where only values are in quotes:
- system: 'android'
nice: false
pass:
- success:
- 'a'
- 'b'
- 'c'
warning:
- pass:
- 'a'
- 'b'
- 'c'
number: 1
What I tried:
from ruamel.yaml import YAML
import sys
from ruamel.yaml.compat import StringIO
yaml = YAML()
yaml.preserve_quotes = True
buf = StringIO()
yaml.dump(t1, buf)
yaml.indent(mapping=2, sequence=4, offset=2)
data = yaml.load(buf.getvalue())
yaml.dump(data, sys.stdout)
but yaml.preserve_quotes = True does not work and output is:
- system: android
nice: false
pass:
- success:
- a
- b
- c
warning:
- pass:
- a
- b
- c
number: 1
What should I do?