|
From: Jason B. <jb...@ze...> - 2010-03-17 16:07:13
|
I'm not really sure how best to phrase my example, so I'll illustrate it
with code. :-)
Suppose I have the following config file:
[section]
foo='bar'
[[subsection]]
Now suppose I do the following:
configobj = <get configobj somehow>
subsection = configobj['section']['subsection']
subsection['foo']
This throws a key error, which is most likely the expected behavior as foo
isn't a key on subsection. However, I would like to have a way to get the
value of foo as if subsection were like this:
[[subsection]]
foo = '$foo'
That way I can fetch the value through the interpolation path rather than
only checking the current section. I suppose I could do something like
this:
try:
return subsection['foo']
except KeyError, ke:
subsection['foo'] = '$foo'
return subsection['foo']
But that feels a bit hacky. Are there any better ways to do this that I'm
not thinking of, or am I just going to have to buck up and put the hack in?
|