Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to deal with YAML in Python

📅 2017-Mar-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

YAML (Yet Another Markup Language) is a language similar to JSON for reading and writing configuration information to files that are human readable. YAML is a superset of JSON. It uses indentation instead of the braces used by JSON.

$ sudo pip install PyYAML
$ sudo pip3 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