How to Load YAML with Python

This post was originally published on Pure Storage

When you need to ingest a YAML (Yet Another Markup Language) file into your Python scripts, you could parse the text yourself or use an available library. A YAML parser library will do all the heavy lifting for you, parse the data, and let you work with it without spending hours writing your own parser. It’s the preferred way for working with YAML files in Python.

PyYAML: The Best YAML Parser for Python

If you review Python code in a repository that parses YAML, you’ll come across PyYAML. The PyYAML library is the most popular module for parsing YAML, and it’s what will be used in this article for code examples. Before you can use PyYAML, you must import the library into your project.

The following command installs and imports PyYAML:

pip install pyyaml

<span style=”font-weight: 400;”>pip install pyyaml</span>

Now, you must add the following line of code at the beginning of your Python project files:

import yaml

<span style=”font-weight: 400;”>import yaml</span>

How to Read, Load, Write YAML without a Library

You might think that parsing YAML without

Read the rest of this post, which was originally published on Pure Storage.

Previous Post

Tangoe Simplifies and De-risks Mobile Device Management

Next Post

5 ways devops can reduce energy consumption