Skip to content Skip to sidebar Skip to footer

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:

Solution 1:

Well I got the answer now. Have some problems with StringIO only, because YAML() always sets the encoding to utf-8 (and allow_unicode = True) Changing to use io doesn't bring anything. If you want to write to a StringIO in 2.7 you'll have to disable the utf-8 encoding:

i.e.

yaml = YAML(typ="safe")
yaml.default_flow_style = Falsestream = StringIO()
yaml.encoding = None

For more info visit this ticket : https://sourceforge.net/p/ruamel-yaml/tickets/271/

Post a Comment for "Transform Attribute In Yaml.dump Is Not Working"