title: Python YAML dump special character and multiple lines
body: <p>I have a <code>my_yaml.yml</code> file with the following content:</p>
  
  <pre><code>my_yaml:
    person: &gt;
      John|Doe|48,
      Jack|Black|39
    skills:
      - name: superhero
        abilities:
          - swim
          - run
    special_chars:
      - '! | " "'
      - '+ | " "'
      - '\ | " "'
      - 'Á | "A"'
      - 'É | "E"'
      - 'Ű | "U"'
      - 'Û | "U"'
  </code></pre>
  
  <p>I want to load it then dump into a <code>my_yaml_new.yml</code> file having totally the same format &amp; characters as the original input file has. My code is:</p>
  
  <pre><code>import yaml
  my_yaml = yaml.load(open('my_yaml.yml', encoding='utf8'))  # without "utf8" encoding I get "'charmap' codec can't decode byte..." error
  </code></pre>
  
  <p>I can <code>dump</code> it into console but <strong>1)</strong> order of <code>abilities</code> &amp; <code>name</code> has changed :(</p>
  
  <pre><code>yaml.dump(my_yaml, default_flow_style=False, allow_unicode=True)
  </code></pre>
  
  <p>Result is:</p>
  
  <pre><code>'my_yaml:\n  person: &gt;\n    John|Doe|48, Jack|Black|39\n  skills:\n  - abilities:\n    - swim\n    - run\n    name: superhero\n  special_chars:\n  - \'! | " "\'\n  - + | " "\n  - \\ | " "\n  - Á | "A"\n  - É | "E"\n  - Ű | "U"\n  - Û | "U"\n'
  </code></pre>
  
  <p>And when I try to dump into a file:</p>
  
  <pre><code>with open('my_yaml_new.yml', 'w') as outfile:
      yaml.dump(my_yaml, outfile, default_flow_style=False, allow_unicode=True)
  </code></pre>
  
  <p><strong>2)</strong> I get the following error due to character <code>Û</code>:</p>
  
  <blockquote>
    <p>UnicodeEncodeError: 'charmap' codec can't encode character '\xdb' in
    position 0: character maps to undefined</p>
  </blockquote>
  
  <p>If I delete this line from the input <code>my_yaml.yml</code> file then above dump is successful, but <strong>3)</strong> my multiple lines at <code>person</code> string go into one line :(</p>
  
  <pre><code>my_yaml:
    person: &gt;
      John|Doe|48, Jack|Black|39
    skills:
    - abilities:
      - swim
      - run
      name: superhero
    special_chars:
    - '! | " "'
    - + | " "
    - \ | " "
    - Á | "A"
    - É | "E"
    - Ű | "U"
  </code></pre>
  
  <p><strong>4)</strong> And also my single quotes (') are disappeared from <code>special_chars</code> :(</p>
  
  <p><strong>5)</strong> And also note that elements of <code>skills</code> has no indentation :(</p>
  
  <p>I've tried <a href="https://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data">these</a> solutions with no success. And nor <code>import ruamel.yaml as yaml</code> has helped.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>OK, the following great package solves problems <strong>1)</strong> &amp; <strong>4)</strong>, and I can replace <code>&gt;</code> to <code>|</code> at multi line values so <strong>3)</strong> is also solved. And maybe <strong>5)</strong> is not a huge problem. But I still struggle with special characters like <code>Û</code> or <code>Ǘ</code> so I'm still looking for solution for problem <strong>2)</strong>...</p>
  
  <pre><code>from ruamel import yaml
  
      my_yaml = yaml.round_trip_load(open('dmy_yaml.yml', encoding='utf8'), preserve_quotes=True)
      with open('my_yaml_new.yml', 'w') as outfile:
          yaml.round_trip_dump(my_yaml, outfile, default_flow_style=False, allow_unicode=True)
  </code></pre>