I wrote a tool that looks in several places for an INI config file: in /usr/share
, /usr/local/share
, ~/.local/share
, and in the current directory.
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
I have started using virtualenv and now my setup.py
script installs myconfig.conf
into /path/to/virtual/env/share/
. How can I add this path to the list of paths searched by ConfigParser when the path to the virtualenv will be different each time? Also, if I installed to a virtualenv, should I still search the system /usr/share
and /usr/local/share
directories?