In this video you'll see a better way to handle complex YAML files: instead of using PyYAML we're going to use Mashumaro.
Once you set up the dataclasses, which are special types of Python classes frquently used to hold simple data, this library loads the file content in their instances. These dataclasses can be nested, reflecting the possible complex structures of a YAML file. Integrating this kind of code in Python program to load configurations greatly simplifies data validation and improves code modularity.
Links
- original blog post: https://blog.franco.net.eu.org/post/s...
- Mashumaro: https://github.com/Fatal1ty/mashumaro
- Dataclasses: https://docs.python.org/3/library/dat...
CHAPTERS
0:00 Intro
0:37 Using PyYAML gets you a dictionary for free
1:18 Thinking about the YAML file as a "container" of different elements
1:27 Creating the class (dataclass) representing the elements of the list
2:39 Dataclass containing the list
4:02 Another dataclass
4:34 The dataclass containing references to all the other dataclasses: this is the root object of a tree representing the YAML file
5:09 Introducing the Mashumaro library
5:47 Mashumaro's YAML functions
6:07 Reading from YAML
6:33 Running the program
7:21 Printing values from the dataclasses
8:46 Callback function for string validation: checking what happens if we change a value type in the YAML file
9:55 More about dataclasses
10:58 Transform a dataclass instance to a dictionary and do more printings
12:20 Outro
#yaml #python #dataclass #mashumaro #programming
On this page of the site you can watch the video online Simpler Python YAML with a duration of hours minute second in good quality, which was uploaded by the user Solve Computer Science 27 January 2024, share the link with friends and acquaintances, this video has already been watched 72 times on youtube and it was liked by 1 viewers. Enjoy your viewing!