1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import sys from ruamel.yaml import YAML inp = """\ # example name: # details family: Smith # very common given: Alice # one of the siblings """ yaml = YAML() code = yaml.load(inp) code['name']['given'] = 'Bob' yaml.dump(code, sys.stdout)