473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6959
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(sec tion)
if x.lower().start swith('ignore_' )]
ignores_list=[]
for option in ignore_options:
ignores_list.ap pend(ini.get(se ction, 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2218
by: Matthew Wilson | last post by:
I'm using ConfigParser to store and retreive some data across multiple runs of my program and it looks like it automatically lower-cases my options: ---this is the program: import ConfigParser cp = ConfigParser.ConfigParser() cp.add_section('info') cp.set('info', 'Previous-IP', '0.0.0.0')
14
1485
by: Michael Chermside | last post by:
A few weeks ago, the suggestion was made on Python-Dev that it might be time to consider replacing the ConfigParser module and that we should hold a "shootout" (ie ask for implementations and see what we get). Since then I've been playing around with this... not the parsing part (which so far I have completely ignored) but the programmer interface. There needs to be a well-thought-out data model for the information stored, and the user...
2
1703
by: rzed | last post by:
I am working with PythonCard in one of my apps. For its purposes, it uses an .ini file that is passed to ConfigParser. For my app, I also need configuration information, but for various reasons, I'd rather use a syntax that ConfigParser can't handle. I know I can maintain two separate configuration files, and if I have to I will, but I'd rather avoid that, if possible, and a solution that suits my purposes is quite straightforward. I...
3
11708
by: mwt | last post by:
I want to set default values for a ConfigParser. So far, its job is very small, so there is only one section heading, . Reading the docs, I see that in order to set default values in a ConfigParser, you initialize it with a dictionary or defaults. However, I'm not quite sure of the syntax to add the section headings in to the dictionary of defaults. For now, I'm doing it like this: default_values = {'username' : 'put username here',...
1
1383
by: Alexandre CONRAD | last post by:
Hello list ! I'm using the ConfigParser module to use configuration files (what else would it be for ?). But I have a dilema: I'd like to setup multiple "update server" for my application with update "priority". At first, I thought about adding a new section in my actual existing config file such as:
12
5361
by: Florian Lindner | last post by:
Hello, since ConfigParser does not seem to support multiple times the same option name, like: dir="/home/florian" dir="/home/john" dir="/home/whoever" (only the last one is read in)
3
7190
by: derf912 | last post by:
I am working with ConfigParser in python and the ini file that I am reading in has a section titled and under that section I have multiple options. All the options have the same name "customer =" Eample: customer = widget1 customer = widget2 customer = widget3 customer = widget4 I am trying to get a list of all the options but have only been able to get the last one to print. Here is the script that I am working with right...
4
14277
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
3
2844
by: Phoe6 | last post by:
Hi, Am starting a new thread as I fear the old thread which more than a week old can go unnoticed. Sorry for the multiple mails. I took the approach of Subclassing ConfigParser to support multiline values without leading white-spaces, but am struct at which position in _read I should modify to accomodate the non-leading whitespace based multiline values.
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.