2 ms·
Shouldn't be much more than a 3-4 lines of code to import from YAML with this library, especially if you have a simple schema: e.g. import strictyaml as s
by crdoconnor 9y ago
Shouldn't be much more than a 3-4 lines of code to import from YAML with this library, especially if you have a simple schema:
e.g.
import strictyaml as sy
MY_TRANSLATIONS_DICT = sy.load(
Path("translations.yml").text(),
sy.MapPattern(sy.Str(), sy.Map({"French": sy.Str(), "German": sy.Str()})),
).data
translations.yml:
Hello:
French: Bonjour
German: Guten Tag
Goodbye:
French: Au revoir
German: Auf wiedersehen
It would negate the need for most of those tests checking for invalid data, too (the above would raise an exception instantly if there is a YAML syntax error or if the data doesn't match the schema).