[Tutor] What is the best way for a program suite to know where it is installed?
__peter__ at web.de
Tue Oct 23 09:02:01 EDT 2018
eryk sun wrote:
> On 10/22/18, boB Stepp <robertvstepp at gmail.com> wrote:
>> Importing the various program modules/module contents is
>> no issue. Where I believe I need to know the paths to things are to
>> get to data folders, config files, and occasionally utility programs
>> that I have written that are on my hard drive, but not copied to my
>> current program suite.
> It's common to use __file__ for a portable application, except you
> should use sys.executable if it's a frozen executable, i.e. if
> sys.frozen exists.
> For an installed application, limit this approach to the application's
> immutable resources. Don't use the installation directory to store
> modifiable data. You may not have write access (e.g. a system
> installation and the user lacks root/admin access, or it's an
> immutable directory or read-only disk mount).
I've not tried it, but for per-app read-only data importlib.resources
appears to be the right tool.
More information about the Tutor