pythonconfigparser

Lists in ConfigParser


The typical ConfigParser generated file looks like:

[Section]
bar=foo
[Section 2]
bar2= baz

Now, is there a way to index lists like, for instance:

[Section 3]
barList={
    item1,
    item2
}

Related question: Python’s ConfigParser unique keys per section


Solution

  • There is nothing stopping you from packing the list into a delimited string and then unpacking it once you get the string from the config. If you did it this way your config section would look like:

    [Section 3]
    barList=item1,item2
    

    It's not pretty but it's functional for most simple lists.