Reading and Writing YAML to a File in Python
Introduction
In this tutorial, we’re going to learn how to use the YAML library in Python 3. YAML stands for Yet Another Markup Language.
In recent years it has become very popular for its use in storing data in a serialized manner for configuration files. Since YAML essentially is a data format, the YAML library is quite brief, as the only functionality required of it is the ability to parse YAML formatted files.
In this article we will start with seeing how data is stored in a YAML file, followed by loading that data into a Python object. Lastly, we will learn how to store a Python object in a YAML file. So, let’s begin.
Before we move further, there are a few prerequisites for this tutorial. You should have a basic understanding of Python’s syntax, and/or have done at least beginner level programming experience with some other language. Other than that, the tutorial is quite simple and easy to follow for beginners.
Installation
The installation process for YAML is fairly straight forward. There are two ways to do it; we’ll start with the easy one first:
Method 1: Via Pip
The easiest