Szymon Lipiński Szymon Lipiński - 3 months ago 8
Python Question

How can I parse a YAML file in Python

How can I parse a YAML file in Python?

Jon Jon
Answer

The easiest and pureist method without relying on C headers is PyYaml:

#!/usr/bin/env python

import yaml

with open("example.yaml", 'r') as stream:
    try:
        print(yaml.load(stream))
    except yaml.YAMLError as exc:
        print(exc)

Err.. that's it... how many lines of code would that take me in Java... any ideas? : ) more info here:

http://pyyaml.org/wiki/PyYAMLDocumentation