Closed dkriegner closed 10 months ago
I tried to use os.path.dirname(__file__)
, but it doesn't work for an exe-file. It uses the path: .../AppData/local/... After restarting the script, CACHE is created new.
Is it a good idea if the script stores the cache file to C:/Users/{username}/AppData/Local/{appname}?
It works!!!
import os
import sys
# Get the path of the executable file
exe_path = sys.executable
print("The path of the executable file is:", exe_path)
# Get the directory name from the path
exe_dir = os.path.dirname(exe_path)
print("The directory of the executable file is:", exe_dir)
Two problems I see:
1) I believe this only works in windows and potentially only when using pyinstaller. In linux I get
$ python GUI/Test.py
The path of the executable file is: /usr/bin/python
The directory of the executable file is: /usr/bin
Press a key!
And /usr/bin is certainly not the directly the CACHE should be placed in. I would say C:/Users/{username}/AppData/Local/{appname} sounds good for Windows. In 2) The command line app still uses the executation directory to store the CACHE
Maybe one could use this package to simplify your life: https://github.com/platformdirs/platformdirs
It would work on all platforms like this:
import platformdirs
platformdirs.user_config_dir("micro-flakes")
Also I believe the CACHE file should likely be compatible with the configparser package. this allows to specify fallback values and make type conversion more straight-forwardly
I integrated the configparser to the code.
I believe the CACHE file needs to be generated in one and the same place, but not in the folder where I execute the script.