4

I need to locally store some basic data the user inputs into my exe. The program was compiled using pyinstaller and was previously making use of the os open method of saving data to txt files. It is my understanding that macOS(my OS although cross-compatibility with Windows would be great) locks executables so that they may not make any file changes. The program currently does save the data, but when the executable is run again the old data is no longer accessible.

It seems obvious that apps store things locally all the time, how can data be persisted specifically within the python/pyinstaller combination?

Apologies if this is a simple question, it definitely seems simple but I can't find documentation for this anywhere.

Vexh HD
  • 41
  • 1
  • 2
  • It is not possible to persist data in the application, you need to save the data in a separate file or database. – Maurice Meyer Jan 28 '19 at 10:20
  • Thank you for your reply. When you say application do you mean the executable itself or just the python script? I'm aware that persisting data within the python script would be impossible, but looking for ways to persist within the executable(possibly by including writable files or databases within the executable. – Vexh HD Jan 28 '19 at 14:36
  • In the end it is the same, if it doesnt work for the script it doesnt work for the executable. So you need to create a writable file in `~/Library/Application Support/yourApplication` or so to persist data. – Maurice Meyer Jan 28 '19 at 15:03

1 Answers1

2

You can use

os.path.expanduser('~user')

to get the user home directory in a cross-platform manner, see How to find the real user home directory using python?

Your application should have write permissions in the user home directory, so then you can let it create and modify a data file there following How to store Python application data.

jpeg
  • 2,372
  • 4
  • 18
  • 31