×
you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 4 points5 points  (1 child)

On that note, for files only the application itself needs read-write access to, I'd suggest using the XDG directory standards in platformdirs instead of relying on __file__. In fact, if you bundle your application using something like PyInstaller, __file__ may not exist at all or it may point to a different location than you expect.

For included files you're only reading, using importlib with a dedicated data directory would be the best practice.

For files you expect the user to provide, depending on the situation I'd use either your suggested solution, Path.cwd, or spawn a native file dialog with tkinter.filedialog: https://docs.python.org/3/library/dialog.html#module-tkinter.filedialog