How can I parse a YAML file in Python

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

How can I parse a YAML file in Python?

Answers

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 http://pyyaml.org/wiki/PyYAMLDocumentation

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/1773805/how-can-i-parse-a-yaml-file-in-python

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils