A Python module I’m developing has a master configuration file in /path/to/module/conf.conf. The /path/to/module/ depends on the platform (for instance, /Users/me/module in OS X, /home/me/module in Linux, etc).
Currently I define the /path/to/module in __init__.py, where I use logic:
if sys.platform == 'darwin':
ROOT = '/Users/me/module'
elif sys.platform == 'linux':
ROOT = '/home/me/module'
# et cetera
Once I have the configuration file root directory, I can open conf.conf anywhere I want.
Do you have a better methodology?
Inside of your
__init__.py, you could get the directory where the__init_.pyscript lives using the__file__magic variable like so:Then you know that
conf.confwill be located atos.path.join(ROOT, 'conf.conf').