yaml.load code 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: read yml file in python

{'a_key': 'a_value', 'another_key': 'another_value', 'nested_dictionary': {'nested_key': 'nested_value'}}

Example 3: yaml dump

>>> print yaml.dump({'name': 'Silenthand Olleander', 'race': 'Human',
... 'traits': ['ONE_HAND', 'ONE_EYE']})

name: Silenthand Olleander
race: Human
traits: [ONE_HAND, ONE_EYE]