ConfigParser, mapping one key to multiple values

Larry Bates lbates at syscononline.com
Wed Jun 1 18:18:42 EDT 2005


I accomplish this by using the following construct
with ConfigParser:

[sync files]
ignore_001=.*/foodir/.*\.pyc
ignore_002=.*/foodir/.*~
.
.
.

It may be a workaround, but it works just fine.

It is easy to write code to handle this (not tested):

section='sync files'
ignore_options=[x for x in ini.options(section)
                if x.lower().startswith('ignore_')]
ignores_list=[]
for option in ignore_options:
    ignores_list.append(ini.get(section, option))



Larry Bates


Thomas Guettler wrote:
> Hi,
> 
> I need a config like this:
> 
> [sync files]
> ignore=".*/foodir/.*\.pyc"
> ignore=".*/foodir/.*~"
> ...
> 
> The ConfigParser of the standard library can't handle this,
> because one key maps to multiple values.
> Is there a simple and lightweight config parser which can
> handle this?
> 
>  Thomas
> 
> PS: Needs to be compatible with Python 2.3
> 



More information about the Python-list mailing list