Ich habe eine Datei, die yaml Lese YAML in Python
---
level_1: "test"
level_2: 'NetApp, SOFS, ZFS Creation'
request: 341570
---
level_1: "test"
level_2: 'NetApp, SOFS, ZFS Creation'
request: 341569
---
level_1: "test"
level_2: 'NetApp, SOFS, ZFS Creation'
request: 341568
Ich bin in der Lage zu lesen, das richtig in Perl YAML aber nicht in Python mit YAML wie
aussieht. Es schlägt mit dem Fehler:expected a single document in the stream
Programm:
import yaml
stram = open("test", "r")
print yaml.load(stram)
Fehler:
Traceback (most recent call last):
File "abcd", line 4, in <module>
print yaml.load(stram)
File "/usr/local/pkgs/python-2.6.5/lib/python2.6/site-packages/yaml/__init__.py", line 58, in load
return loader.get_single_data()
File "/usr/local/pkgs/python-2.6.5/lib/python2.6/site-packages/yaml/constructor.py", line 42, in get_single_data
node = self.get_single_node()
File "/usr/local/pkgs/python-2.6.5/lib/python2.6/site-packages/yaml/composer.py", line 43, in get_single_node
event.start_mark)
yaml.composer.ComposerError: expected a single document in the stream
in "test", line 2, column 1
but found another document
in "test", line 5, column 1
Zur Bezugnahme siehe Kapitel 2 (Syntax) von http://www.yaml.org/spec/1.2 /spec.html. Es ist ein 5 Minuten gelesen und es wert. – Titou
Siehe [Wie kann ich eine YAML-Datei in Python analysieren] (https://stackoverflow.com/a/42054860/562769) –