this post was submitted on 14 Jul 2023
7 points (100.0% liked)

Python

6134 readers
4 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

I have a use case where I'd like to store a handful of strings with static values, alongside my code that references them. The general reason for not hard coding them where they're called, is that I'd like to make it easy for the end user to customize and modify them.

Are there any suggestions or comments about the best ways to do this? Storing them in a python file as vars seems reasonable. I've also considered saving them as JSON, though I don't know if there's any benefit to that in this case.

Thoughts are appreciated.

you are viewing a single comment's thread
view the rest of the comments
[–] rhacer@lemmy.world 5 points 1 year ago (1 children)

How many? I probably wouldn't even bother with JSON, just one string per line in a text file.

[–] wesker@lemmy.sdf.org 1 points 1 year ago (1 children)

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.

[–] rhacer@lemmy.world 6 points 1 year ago

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.