Dec 22, 2017 - This post will guide you through the (strange) ways of the various YAML parsers by using Ruby and Python examples and comparing their.
The Official YAML Web Site%YAML 1.2 --- YAML: YAML Ain't Markup Language What It Is: YAML is a human friendly data serialization standard for all programming languages.
If you have YAML that conforms to the (released 2009) then you should use (disclaimer: I am the author of that package). It is essentially a superset of PyYAML, which supports most of YAML 1.1 (from 2005). If you want to be able to preserve your comments when round-tripping, you certainly should use ruamel.yaml. Upgrading @Jon's example is easy: import ruamel.yaml as yaml with open('example.yaml') as stream: try: print(yaml.safe_load(stream)) except yaml.YAMLError as exc: print(exc) Use safe_load() unless you really have full control over the input, need it (seldom the case) and know what you are doing. If you are using pathlib Path for manipulating files, you are better of using the new API ruamel.yaml provides: from ruamel.yaml import YAML from pathlib import Path path = Path('example.yaml') yaml = YAML(typ='safe') data = yaml.load(path).