Reputation: 421
I am creating a small application in Python that needs to read a configuration file.
I intend to save this file in a folder in /etc
on Linux, but I would like my application to run on other operating systems.
The question is: Is there some kind of constant, variable, package, etc. that can tell me the path to the most sensible settings folder on an OS?
Upvotes: 0
Views: 3627
Reputation: 1723
Maybe it is better to locate your configuration file(s) in a folder related to your actual module/application? Determine the location of your module might not be straight forward, but this thread should help.
One tool which maybe useful, configparser, has a function which actually looks for configuration files in some standard locations: RawConfigParser.read(filenames)
Upvotes: 3
Reputation: 2664
As far as I know there is no builtin constant for this, but it seems fairly easy to do it manually.
You could use sys.platform
or os.name
to get the OS, and then set the config folder according to this.
os_name = sys.platform
cfg_folder = {'linux2': '/etc', 'win32': 'folder', ...}[os_name]
Upvotes: 2
Reputation: 235
You might want to check http://docs.python.org/library/os.html#os-file-dir . After getting the root path you are able to select specific paths depending on the working OS.
Upvotes: 1