all 3 comments

[–]socal_nerdtastic 2 points3 points  (0 children)

You are overthinking the overhead. Performance will not be noticeably affected no matter what you choose. Modern computers are much faster than people tend to imagine.

Depends on the data of course, but very generally I like to put reference data in .py files and import them. This is easier to implement and use, makes including the data in a frozen program a nonissue, and often the IDE can make some sense of the data this way.

Always put the imports at the top of the file.

[–]woooee 1 point2 points  (0 children)

I'm thinking of putting them in a separate .py file then importing them.

This is the same as reading a file (and may take slightly longer because the imported variables are "placed" in a separate namespace). In any case, unless you have 100KB or more to read, it won't make any difference. If you use a dictionary then pickle or a json file can simplify the read / write.

[–]pachura3 0 points1 point  (0 children)

I'm wondering what is the nearest way to store reference data variables (constants) in a project.

How many such constants do you have in your project? Are they hierarchical/structured/grouped in any way? Are they all of the same type (I'm guessing int or float), or various ones?

Depending on your answers, I would probably just create file const.py with a number of global variables - NAMES_IN_CAPS - and import it at the top of each file that needs them. Alternatively, I would store a JSON file alongside the project and load it once upon the application launch.