|
From: Nicola L. <ni...@te...> - 2006-12-12 11:44:10
|
Michael Holzt wrote:
> I have severe problems getting interpolation work for me. I have a
> config file with e.g. the following content:
>
> | [object]
> | field1: test test test %(uid)s
The ':' keyword/value separator character is not allowed by ConfigObj, only
the '=' one is.
> The uid-value is not defined in the config file but shall be set on
> runtime. I can't figure out how to set the value, i always end up
> with 'MissingInterpolationOption' or other errors (e.g. KeyError).
>
> I tried for example config['DEFAULT']['uid'] = 'user' (KeyError),
> config['uid'] = 'user' (MissingInterpolationOption). I'm sure i
> make a simple mistake, but i can't figure it out. Some help would
> be appreciated.
The following code uses the SVN repo, the interpolation logic changed from
v.4.3.2 .
>>> from pythonutils import configobj
>>> cfgList = ['[object]', 'field1 = test test test %(uid)s']
>>> cfg = configobj.ConfigObj(cfgList, interpolation = 'ConfigParser')
>>> cfg['object']['field1']
Traceback (most recent call last):
...
raise MissingInterpolationOption(key)
pythonutils.configobj.MissingInterpolationOption: missing option "uid"
in interpolation.
>>> cfg['DEFAULT'] = {}
>>> cfg['DEFAULT']['uid'] = 'outer_default'
>>> cfg['object']['field1']
'test test test outer_default'
>>> cfg['uid'] = 'outer'
>>> cfg['object']['field1']
'test test test outer'
>>> cfg['object']['DEFAULT']['uid'] = 'inner_default'
>>> cfg['object']['field1']
'test test test inner_default'
>>> cfg['object']['uid'] = 'inner'
>>> cfg['object']['field1']
'test test test inner'
--
Nicola Larosa - http://www.tekNico.net/
Ubuntu is everything you love about Debian, and none of what you don't.
Package management that "just works" 99% of the time, a good community
to help if it doesn't, and actual releases. -- Jason Clark, May 2006
|