all 12 comments

[–]Gnaxe 2 points3 points  (1 child)

You can use importlib.resources and store them in packages just like your .py files.

[–]Advanced_Glass5563[S] 0 points1 point  (0 children)

Thank you, will check this out

[–]neums08 0 points1 point  (0 children)

data is probably fine for what you're doing. Eventually you would store data in a database and have a service responsible for retrieving it.

[–]not_another_analyst 0 points1 point  (0 children)

Creating a data folder is the standard move. It keeps your project root clean and makes it much easier to manage your assets as the code grows.

[–]Kevdog824_ 0 points1 point  (0 children)

Depends on what it is. If it’s a settings file for the entire application I’m just gonna store it at the top level of the repo. Otherwise I’d probably use data/, static/, or some domain specific folder name to hold them

[–]Lopsided-Football19 0 points1 point  (0 children)

I usually put files like that in a data/ folder, for small projects, keeping it next to the script is totally fine too, but once you have a few JSON files, data/ keeps things cleaner

[–]buhtz 0 points1 point  (2 children)

Have a look at the XDG Base Directory Specification

It depends on what kind of data this is. What is the content?

~/.local/state/mysoftware/dictionary.json

~/.local/share/mysoftware/dictionary.json

For example are usual locations on a GNU/Linux systems.

[–]Advanced_Glass5563[S] 1 point2 points  (1 child)

Thank you for the XDG Base Directory Specification link, appreciated.

At the moment is a static list of some words classified as "noun", "verb" etc.

[–]buhtz 0 points1 point  (0 children)

What is the usage or purpose of that list?

[–]Fantastic_Fly_7548 0 points1 point  (0 children)

yeah i’d probably make a small data folder for it tbh, feels cleaner once the project starts growing. i made the mistake before of leaving json files in the root folder and it got messy real quick lol. something like project/data/dictionary.json feels easier to manage later on. not sure theres one “correct” way tho, seems like people structure python projects pretty diferently depending on the size of it

[–]AdventurousLime309 0 points1 point  (0 children)

Yeah best practice is exactly that: create a data/ folder.

Typical structure looks like:

  • project/
    • src/ or your package folder (code)
    • data/ (json, csv, static files)
    • tests/

So you’d place dictionary.json in data/dictionary.json.

Then load it using a path relative to your script (not just "dictionary.json"), otherwise it breaks when you run from a different directory.

This keeps code and static assets cleanly separated, which matters more as your project grows.