Skip to content

yaml - python

Load

import yaml
with open('a.yml', 'r') as f:
    data = yaml.load(f, Loader=yaml.CLoader)
  • Load all
    • multiple yamls in the same file splitted by ---
for data in yaml.load_all(documents):
    print(data)

Dump

import yaml
with open('a.yml', 'w') as f:
    f.write(yaml.dump(f, Dumper=yaml.CDumper))

References

PyYAML Documentation
https://pyyaml.org/wiki/PyYAMLDocumentation