title: How do I append to a YAML file with python
body: <p>I have a YAML file called <code>data.yaml</code>: </p>
  
  <pre><code>---
  '001':
    name: Ben
    email: ben@test.com
  </code></pre>
  
  <p>I would like to have an updated file that looks like this: </p>
  
  <pre><code>---
  '001':
    name: Ben
    email: ben@test.com
  '002':
    name: Lisa
    email: lisa@test.com
    numbers: 
      - 000-111-2222
      - 000-111-2223
  </code></pre>
  
  <p>How do I achieve this in python using yaml package/s?</p>
  
  <p>Edit: </p>
  
  <p>I have tried: </p>
  
  <pre><code>import yaml
  import io
  
  data = {'002': {'name': 'Lisa', 'email': 'lisa@test.com', 'numbers': ['000-111-2222', '000-111-2223']}}
  
  with io.open('data.yaml', 'w', encoding='utf8') as outfile:
      yaml.safe_dump(data, outfile, default_flow_style=False, allow_unicode=True)
  </code></pre>
  
  <p>Method <em>safe_dump</em> overrides the file content and I only see this as the new file content!</p>
  
  <pre><code>'002':
    name: Lisa
    email: lisa@test.com
    numbers: 
      - 000-111-2222
      - 000-111-2223
  </code></pre>