# 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)
Here is what the above code is Doing:
1. Open the data.yaml file in read mode.
2. Load all the documents in the file using yaml.load_all().
3. Iterate over all the documents.
4. Print the key and value pairs.