ENVIRONMENT Variable expansion in ConfigParser

pikespeak krishnan.snowboarder at gmail.com
Thu Oct 14 19:57:57 EDT 2010


Hi,
I am using ConfigParser module and would like to know if it has the
feature to autoexpand environment variables.
For example currently, I have the below section in config where
hostname is hardcoded.
I would like it to be replaced with the values from the env variable
os.envion['HOSTNAME'] so that I can remove hardcoding and my config
will be host independent.

[section]
host.name=devserver1.company.com

to be replaced with something like this

[section]
host.name=os.environ['HOSTNAME']

I know of the interpolation feature of Config Parser %{foo}s  where
value of foo will be expanded..but not sure if this can be tweeked to
my needs.

Any ideas please.

srini




More information about the Python-list mailing list