pyyaml example
Example 1: python read yaml
# read_categories.py file
import yaml
with open(r'E:\data\categories.yaml') as file:
documents = yaml.full_load(file)
for item, doc in documents.items():
print(item, ":", doc)
Example 2: python yaml load_all
# pip install pyyaml
import yaml
with open('data.yaml') as f:
docs = yaml.load_all(f, Loader=yaml.FullLoader)
for doc in docs:
for k, v in doc.items():
print(k, "->", v)