Transform attribute in yaml.dump is not working
问题 If we want to alter the output of yaml.dump we can use tranform keyword argument. Documentation: https://yaml.readthedocs.io/en/latest/example.html Here is the yaml data: metadata: name: name alias: alias it is stored in variable x. x = 'metadata:\n name: name\n alias: alias\n' def tr(s): return s.replace('\n', '\n ') # Want 4 space at each new line from ruamel.yaml import YAML from ruamel.yaml.compat import StringIO yaml = YAML(typ="safe") yaml.default_flow_style = False stream = StringIO()