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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top