Default Section Values in ConfigParser

Terry Hancock hancock at
Wed Mar 1 04:13:39 CET 2006

On 28 Feb 2006 17:05:32 -0800
"mwt" <michaeltaft at> wrote:
> I want to set default values for a ConfigParser. So far,
> its job is very small, so there is only one section
> heading, ['Main']. Reading the docs, I see that in order
> to set default values in a ConfigParser, you initialize it
> with a dictionary or defaults.

You know, I never noticed that, but there is another way.

I used a multi-line string constant with the same syntax
as the original file, and just fed that in as the first
source (this is particularly easy, so I think it must have
been intended).  Slightly snipped version of my code for

default_cfg = StringIO("""\


# Look for varimage.cfg in 3 possible locations:
config = ConfigParser.ConfigParser()
   os.path.join(pkghome, 'varimage.cfg') ])

Terry Hancock (hancock at
Anansi Spaceworks

More information about the Python-list mailing list