【发布时间】:2010-10-21 14:20:52
【问题描述】:
我编写了一个工具,它在多个位置查找 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 目录吗?
【问题讨论】:
标签: python virtualenv configparser