ENVIRONMENT Variable expansion in ConfigParser

P

pikespeak

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
 
R

Rodrick Brown

How about doing something like

host.name=%HOSTNAME%

Then when you parse in the value %HOSTNAME% from your configParser module you do a pattern substitution of %HOSTNAME% with os.environ['HOSTNAME'].

Sent from my iPhone 4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top