Read, Parse & Write YAML Files Using Python 3 & pyyaml

0Shares

First of all, install the pyyaml package using pip in the command line.

pip install pyyaml

code.py

import yaml

with open(r'file.yaml') as file:
    # The FullLoader parameter handles the conversion from YAML
    # scalar values to Python the dictionary format
    fruits_list = yaml.load(file, Loader=yaml.FullLoader)

    print(fruits_list)
0Shares

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.