Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created March 11, 2021 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/9c0b78a1e5e3eabe96372725ec230daa to your computer and use it in GitHub Desktop.
Save SamSaffron/9c0b78a1e5e3eabe96372725ec230daa to your computer and use it in GitHub Desktop.
from ruamel.yaml import YAML
import sys
example = """
# hello
test: "test\\ntest\\ntest" # a test
test2: hello.. #world
"""
rt_yaml=YAML(typ='rt')
parsed = rt_yaml.load(example)
parsed['world'] = "hello"
parsed['test2'] = "test2"
rt_yaml.dump(parsed, sys.stdout)
# output:
# # hello
# test: "test\ntest\ntest" # a test
# test2: test2 #world
# world: hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment