3 ms·
Since you're using python and you're trying to store configuration style data in something that you might want a non-programmer to maintain, might I suggest sto
by crdoconnor 9y ago
Since you're using python and you're trying to store configuration style data in something that you might want a non-programmer to maintain, might I suggest storing the data as YAML and parsing with my library?
https://github.com/crdoconnor/strictyaml https://github.com/crdoconnor/strictyaml
I wrote it partly to make it easier for non-programmers to maintain structured data - which seems to be your use case. YAML is cleaner and easier to maintain than python dicts/lists/etc, and with a strictly validated schema you can trigger failures caused by accidental insertion of invalid data at an earlier stage.
- danpalmer 9y agoThanks, I'll consider it for the future! Python has worked fairly well for us so far though, we have tests that would detect invalid syntax, and importing a Python file is easier than parsing and doing the error handling on YAML/JSON.
- crdoconnor 9y agoShouldn'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).