7
submitted 1 year ago* (last edited 1 year ago) by wesker@lemmy.sdf.org to c/python@programming.dev

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
[-] lasagna@programming.dev 2 points 1 year ago* (last edited 1 year ago)

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.

[-] wesker@lemmy.sdf.org 2 points 1 year ago

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!

@wesker @lasagna customtkinter for visually better interface.

[-] o11c@programming.dev 1 points 1 year ago

Note that by messing with a particular module's __path__ you can turn it into a "package" that loads from arbitrary directories.

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

Python

6356 readers
8 users here now

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

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS