I always use a yaml file for user config but json is fine, too
Yaml is pure evil with utterly useless syntax checking.
Ever tried maintaining a Swagger file using yaml?
I'm never touching that shit again.
YAML is far from perfect but this seems like a hot take. I work with OpenAPI definitions a lot so I'm just curious what you found difficult about maintaining a definition in YAML?
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.
I'd absolutely use a text file, one entry per line. Once you need to start associating other information with those strings, it becomes time for JSON or similar.
json schema + json allows you to extend beyond key/value pairs & the input validation is "free".
use configparser if you want user configuration
This is a great lead, thank you!
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.
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.
Python
Welcome to the Python community on the programming.dev Lemmy instance!
📅 Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django 💬)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
🐍 Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
💓 Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
✨ Python Ecosystem:
🌌 Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- Pythörhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API