Skip to content

Instantly share code, notes, and snippets.

@moreati
Created January 20, 2019 14:45
Show Gist options
  • Save moreati/8cdefd100c6c5267bc58f7f72cb66c39 to your computer and use it in GitHub Desktop.
Save moreati/8cdefd100c6c5267bc58f7f72cb66c39 to your computer and use it in GitHub Desktop.
from cStringIO import StringIO
import sys
import ruamel.ordereddict
import ruamel.yaml
s = '''\
foo:
bar: baz
a: 1
# comment
c: |-
qwertyuiop
asdfghjkl
zxcvbnm
'''
yaml = ruamel.yaml.YAML()
yaml.version = 1,1
yaml.indent(sequence=4, offset=2)
yaml.sort_base_mapping_type_on_output = True
data = yaml.load(StringIO(s))
data['foo'] = dict(data['foo'])
yaml.dump(data, sys.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment