Combine Template And `configparser`
I have a template file called foo.cfg: [Box] box.active={box_activate} resolution_tracker.active=true box.api_key={box_api_key} box.api_secret={box_api_secret} box.job_interval=480
You can format the keys and use StringIO
to create a file-like object to pass to ConfigParser's readfp
method:
from StringIO import StringIO
# ...
with open('foo.cfg') as foo:
fixed = foo.read().format(**keys)
parser = ConfigParser.ConfigParser()
parser.readfp(StringIO(fixed))
# ...
Post a Comment for "Combine Template And `configparser`"