I always use a yaml file for user config but json is fine, too
post
How many? I probably wouldn't even bother with JSON, just one string per line in a text file.
Sorry, I should have given more detail about the nature of the strings.
Right now it's about ~15, however that could grow to maybe a maximum of 30. Some are short sentences, but others might be a couple sentences long.
json schema + json allows you to extend beyond key/value pairs & the input validation is "free".
use configparser if you want user configuration
By any chance, is the reason for this to translate to different languages? If so I'd recommend using hertest. It's a UNIX tool which python has standard library support for: https://docs.python.org/3/library/gettext.html
It's not, but thank you for the thoughtful response.
I'm building a MUD server framework. I'd like to allow some of the high level event messages easily modified, should the builders/admins desire to have a totally customized experience.
Honestly you probably should think about how to translate them. Python at least rolls its own .mo parser so it can support multiple languages in a single process; it's much more difficult in C unless you push it to the clients (which requires pushing the parameterization as well).
Non-.pot-based internationalization formats are almost always braindead and should be avoided.
If you don't care too much about how it looks then you could just straight up have a Python dictionary in a separate file then just import it into main code.
If you want something more formal looking (or expect rather dumb users) then perhaps something like tkinter that draws default values from a file such as the above. Tkinter can enforce input types and such quite easily too.
I'm not familiar with tkinter. This is an amazing suggestion. If not for this particular use case, I very well may use it for a completely different one I still need a solve for. Thanks!
Note that by messing with a particular module's __path__ you can turn it into a "package" that loads from arbitrary directories.
top 16 comments