I am using SafeConfigParser, my configuration file includes a [DEFAULT] section and I am using the below code to extract that part.
parser = SafeConfigParser(allow_no_value=True)
parser.optionxform = str # makes names case sensitive
defaultAttributesDic = parser.defaults()
However my DEFAULT section include interpolated values such as:
A= 10000
B= %(A)s
But the problem is that defaults() returns the actual raw values (not interpolated values).
Why is that? when can that be useful? I don’t get the reason behind this decision?
I am using parser.items(section) to read other sections and that works fine. Values are returned interpolated. Should i skip defaults and use items("DEFAULT") instead? Please explain this to me?
defaults() is a method inherited from RawConfigParser which doesn’t support interpolation.
I think you should reserve the
[DEFAULT]section for providing defaults for other sections instead of trying to “abuse” it as a “normal” section. The[DEFAULT]section has a special meaning and isn’t even included in methods likesections()orhas_section().If you need a “default” section just call it a name other than
DEFAULT.