Preserve quotes and also add data with quotes in Ruamel
<p>I am using Ruamel to preserve quote styles in human-edited YAML files.</p>

<p>I have example input data as:</p>

<pre><code>---
a: '1'
b: "2"
c: 3
</code></pre>

<p>I read in data using:</p>

<pre><code>def read_file(f):
    with open(f, 'r') as _f:
        return ruamel.yaml.round_trip_load(_f.read(), preserve_quotes=True)
</code></pre>

<p>I then edit that data:</p>

<pre><code>data = read_file('in.yaml')
data['foo'] = 'bar'
</code></pre>

<p>I write back to disk using:</p>

<pre><code>def write_file(f, data):
    with open(f, 'w') as _f:
        _f.write(ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper, width=1024))

write_file('out.yaml', data)
</code></pre>

<p>And the output file is:</p>

<pre><code>a: '1'
b: "2"
c: 3
foo: bar
</code></pre>

<p>Is there a way I can enforce hard quoting of the string 'bar' without also enforcing that quoting style throughout the rest of the file?</p>

<p>(Also, can I stop it from deleting the three dashes <code>---</code> ?)</p>