I'm having a hard time escaping single quotes when adding new values to yaml with ruamel.yaml.
Below is what I am doing
import sys
from ruamel.yaml import YAML
yaml_doc = """\
Mappings:
Values:
'123': 'no'
"""
yaml = YAML()
yaml.preserve_quotes = True
data = yaml.load(yaml_doc)
new_value = data['Mappings']['Values']
new_value.insert(len(new_value), '456','' 'no'' ', comment="New Value")
new_value.insert(len(new_value), '789',' ''no' '', comment="New Value 2")
yaml.dump(data, sys.stdout)
With this code I always get a leading or trailing space after/before the no for the values I've inserted.
Mappings:
Values:
'123': 'no'
'456': 'no ' # New Value
'789': ' no' # New Value 2
How can I insert the no value with single quotes but no trailing/heading space?