June 2019
Beginner to intermediate
770 pages
19h 24m
English
When we write YAML files, we generally do something like this:
from pathlib import Pathimport yamlwith Path("some_destination.yaml").open("w", encoding="UTF-8") as target:
yaml.dump(some_collection, target)
We open the file with the required encoding. We provide the file object to the yaml.dump() method; the output is written there. When we read YAML files, we will use a similar technique:
from pathlib import Pathimport yamlwith Path("some_source.yaml").open(encoding="UTF-8") as source: objects= yaml.load(source)
The idea is to segregate the YAML representation as text from any conversion to bytes on the resulting file. We have several formatting options to create a prettier YAML representation of our data. ...
Read now
Unlock full access