Parsing environment variables in ConfigParser files

Andrew Dalke adalke at mindspring.com
Fri Dec 19 12:43:43 EST 2003


Matthew Barnes:
> I'm considering submitting a patch for Python 2.4 to allow environment
> variable expansion in ConfigParser files.  [...]  I'd like to be
> able to specify something like the following in a configuration file:
>
>         [section_name]
>         data_file=${HOME}/mydata.dat

Personally, I'm against it.  The less magic the better.  Eg,
what if I have a configuration file which sets the default
configurations, so that I want the actual string
  ${HOME}/mydata.dat
in the file.  What's the escape rule for that.

Whereas as it is now I can get the string value then use
os.path.expandvars (or os.path.expanduser if I want ~home
expansion).  It's an extra couple lines of code, granted,
but it's explicit instead of implicit and less likely to introduce
subtle errors.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list