ConfigParser: writes a list but reads a string?

Frithiof Andreas Jensen frithiof.jensen at
Mon Jan 16 07:17:27 EST 2006

"Terry Carroll" <carroll at> wrote in message
news:dehms1tm2ktf7r5jnieathatlo4lj799no at
> It looks like ConfigParser will accept a list to be writing to the
> *.ini file; but when reading it back in, it treats it as a string.

ConfigParser is nasty because it does not really support type conversions
but still permits writing incompatible types to the configuration - i.e. the
conversions are generally one-way. It probably will croak on Floats in the
same way. The "string interpolation" works in mysterious ways too.

If you need ConfigParser to work then let every config item be strings and
convert manually as necessary.

> Is there a pythonic way to read in a list from a .INI file with
> ConfigParser?  Is this expected behavior for ConfigParser?

Not in the way we normally use "expected" - but with ConfigParser it is to
be expected ;-)

> I would
> not expect this conversion; rather, an exception when trying to write
> the list if the list is not supported.

If you want both text format config files and types that work then use
"ZConfig" instead.


ZConfig has no built-in way of writing a configuration - but this is not a
severe limitation: If the configuration is split into a "static-", which get
updated before a run and a "state-" set of files with things that are
changed by the application it is easier to keep the configuration consistent
anyway (it is not so hard to dump a dict into a ZConfig format).

More information about the Python-list mailing list