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
Auf dieser Seite können Sie das Online-Video Simpler Python YAML mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Solve Computer Science 27 Januar 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 72 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!