我编写了一个工具,它在多个位置查找 INI 配置文件:在/usr/share
、/usr/local/share
、~/.local/share
和 当前目录中。
c = ConfigParser.RawConfigParser()
filenames = ['/usr/share/myconfig.conf',
'/usr/local/share/myconfig.conf',
os.path.expanduser('~/.local/share/myconfig.conf'),
os.path.expanduser('./myconfig.conf')]
parsed_names = c.read(filenames)
for name in parsed_names:
print 'using configuration file: ' + name
我已经开始使用 virtualenv,现在我的setup.py
脚本安装myconfig.conf
到/path/to/virtual/env/share/
. 当 virtualenv 的路径每次都不同时,如何将此路径添加到 ConfigParser 搜索的路径列表中?另外,如果我安装到 virtualenv,我还应该搜索系统/usr/share
和/usr/local/share
目录吗?