469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

ConfigParser, mapping one key to multiple values

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

--
Thomas GŁttler, http://www.thomas-guettler.de/
Jul 19 '05 #1
2 5740
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

Jul 19 '05 #2
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

--
Thomas GŁttler, http://www.thomas-guettler.de/
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matthew Wilson | last post: by
14 posts views Thread by Michael Chermside | last post: by
2 posts views Thread by rzed | last post: by
3 posts views Thread by mwt | last post: by
1 post views Thread by Alexandre CONRAD | last post: by
12 posts views Thread by Florian Lindner | last post: by
3 posts views Thread by derf912 | last post: by
4 posts views Thread by Phoe6 | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.