Reading YAML file with Python results in yaml.composer.ComposerError: expected a single document in the stream
The yaml documents are separated by ---
, and if any stream (e.g. a file) contains more than one document then you should use the yaml.load_all
function rather than yaml.load
. The code:
import yamlstream = open("test", "r")docs = yaml.load_all(stream)for doc in docs: for k,v in doc.items(): print k, "->", v print "\n",
results in for the input file as provided in the question:
request -> 341570level_1 -> testlevel_2 -> NetApp, SOFS, ZFS Creationrequest -> 341569level_1 -> testlevel_2 -> NetApp, SOFS, ZFS Creationrequest -> 341568level_1 -> testlevel_2 -> NetApp, SOFS, ZFS Creation