title: PyYAML dump format
body: <p>I know there are a few questions about this on StackOverflow, but I couldn't find what I was looking for.</p>
  <p>I'm using <a href="http://pyyaml.org" rel="nofollow noreferrer">pyyaml</a> to read (<code>.load()</code>) a <code>.yml</code> file, modify or add a key, and then write it (<code>.dump()</code>) again. The problem is that I want to keep the file format post-dump, but it changes.</p>
  <p>For example, I edit the key <code>en.test.index.few</code> to say <code>&quot;Bye&quot;</code> instead of <code>&quot;Hello&quot;</code>.</p>
  <p><strong>Python:</strong></p>
  <pre class="lang-python prettyprint-override"><code>with open(path, &quot;r&quot;, encoding = &quot;utf-8&quot;) as yaml_file:
      self.dict = yaml.load(yaml_file)
  </code></pre>
  <p>Then, after changing the key:</p>
  <pre class="lang-python prettyprint-override"><code>with open(path, &quot;w&quot;, encoding = &quot;utf-8&quot;) as yaml_file:
      dump = pyyaml.dump(self.dict, default_flow_style = False, allow_unicode = True, encoding = None)
      yaml_file.write( dump )
  </code></pre>
  <p><strong>Yaml:</strong></p>
  <p><em>Before:</em></p>
  <pre class="lang-yaml prettyprint-override"><code>en:
    test:
      new: &quot;Bye&quot;
      index:
        few: &quot;Hello&quot;
    anothertest: &quot;Something&quot;
  </code></pre>
  <p><em>After:</em></p>
  <pre class="lang-yaml prettyprint-override"><code>en:
    anothertest: Something
    test:
      index:
        few: Hello
      new: Bye
  </code></pre>
  <p>Is there a way to keep the same format?
  For example the qoutes and order. Am I using the wrong tool for this?</p>
  <p>I know maybe the original file it's not entirely correct, but I have no control over it (it's a Ruby-on-Rails i18n file).</p>
  <p>Thank you very much.</p>