2
我正在開發的Python模塊有一個主配置文件/path/to/module/conf.conf
。 /path/to/module
/取決於平臺(例如,OS X中的/Users/me/module
,Linux中的/home/me/module
等)。定義模塊配置文件的路徑
目前我定義了/path/to/module
在__init__.py
,在這裏我用的邏輯:
if sys.platform == 'darwin':
ROOT = '/Users/me/module'
elif sys.platform == 'linux':
ROOT = '/home/me/module'
# et cetera
一旦我在配置文件根目錄下,我可以打開conf.conf
任何地方我想要的。
你有更好的方法嗎?