Search code examples
pythonwindowscx-freeze

Where should I save the data of my app?


I've just freezed with Cx_freeze a small app which works on windows. I'm aware that I can save some date in database (I'm using sqlite3). But the app needs at some point to create a folder to save drafts written by the user, and it's not working. I don't have the right to create a folder. enter image description here The code :

if not os.path.exists('drafts'):
    os.makedirs('drafts')

It worked great when I was testing it in a folder in 'Documents', but not after freezing. Actually, that's not really a surprise given where I'm trying to create the folder. So, I'd like to know where I should save the files (these are text files). I'm also getting this error, with the code

commande = sqlite3.connect ('Base_de_donnees.db')

enter image description here I have no ideo of why this one is not working, but it's probably linked to the first error.. Thanks for any enlightment


Solution

  • The User's application specific data directory is stored in the environment variable APPDATA. Do something like:

    my_app_name = 'my_app'
    my_app_data_dir = os.path.join(os.environ['APPDATA'], my_app_name)