What is the best way to parse a YAML file in Python?
+6
A:
The easiest and pureist method without relying on C headers is PyYaml:
#!/usr/bin/env python
import yaml
stream = file("example.yaml", 'r')
print yaml.load(stream)
Err.. that's it... how many lines of code would that take me in Java... any ideas? : ) more info here:
Jon
2009-11-21 00:23:34
+1 Recommendation, code sample, and documentation link.
hughdbrown
2009-11-21 03:50:00
The use of `file()` is deprecated; in Python 3.x it has been removed. The use of `open()` works on all versions of Python.
steveha
2009-11-21 06:35:45
in Java it is also a couple of lines:http://code.google.com/p/snakeyaml/wiki/readme#Documentation
2009-11-23 14:26:06
A couple is 2... that's 5 lines of code... :)
Jon
2009-11-23 16:26:41