ConfigParser, mapping one key to multiple values

  • Thread starter Thomas Guettler
  • Start date
T

Thomas Guettler

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
 
L

Larry Bates

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
 
T

Thomas Guettler

Am Wed, 01 Jun 2005 17:18:42 -0500 schrieb Larry Bates:
I accomplish this by using the following construct
with ConfigParser:

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

Hi,

I found out, that you can have newlines in the value:

ignore_regex =
.*/CVS(/.*)?$
.*/\.cvsignore$
.*\.pyc$
.*/\.#

If you call split() on the value, you get the list you need.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,240
Messages
2,571,211
Members
47,847
Latest member
ShavonneLa

Latest Threads

Top