Wednesday, February 26, 2014

YAML parsing in Python with PyYAML

I was looking for a simple way of validating YAML structures, so I did the following:
download http://pyyaml.org/download/pyyaml/PyYAML-3.10.tar.gz
tar xvfz PyYAML-3.10.tar.gz
cd PyYAML-3.10
python setup.py install
python
import yaml
mydomains=yaml.load("""
domains:
  osbpl1do:
    soauser: soa
    optpath: /opt
  osbpl2do:
    soauser: soa2
    optpath: /opt2
  osbpl3do:
    soauser: soa3
    optpath: /opt3
""")
print mydomains
print mydomains['domains']
print mydomains['domains']['osbpl2do']


It works like wonder.
Here more doc.



No comments: