Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to deal with YAML in Python

📅 2017-Mar-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ json, python, pyyaml, yaml ⬩ 📚 Archive

YAML (Yet Another Markup Language) is a language for reading and writing configuration information to files. It is easy to read and write by both humans and computers. YAML also happens to be a superset of JSON. It uses indentation instead of the braces used by JSON.

$ python3 -m pip install PyYAML
import yaml
y = yaml.load(open("foobar.yaml"))
yaml.dump(y, open("foobar.yaml", "w"))
yaml.dump(y, open("foobar.yaml", "w"), default_flow_style=False)

Tried with: PyYAML 3.11, Python 3.5.2 and Ubuntu 16.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧