473,498 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading a config file

hi
i used ConfigParser to read a config file. I need the config file to
have identical sections. ie :

[server]
blah = "some server"
[destination]
blah = "some destination"
[end]
end= ''

[server]
blah = "some other server"
[destination]
blah = "some other destination"
[end]
end=''

and i need to check that every 'server' and 'destination' is followed
by 'end'

if i used the 'sections' method, it always show 'server' and
'destination' and 'end'. how can i iterate all the sections. ie..

for s in cfg.sections():
do something...

or is naming all the sections with different names is a better option?
thanks

Nov 4 '05 #1
1 2040
When I need something like this I have employed the following:

[server_001]
blah = "some server"
destination="some destination"

[server_002]
blah = "some other server"
destination="some other destination"

[server_linux1]
blah = "some other server"
destination="some other destination"
Then I do something like this:

import ConfigParser
INI=ConfigParser.ConfigParser()
INI.read(inifilename)
serversections=[x for x in INI.sections if x.startswith('server_')]
for serversection in serversections:
servername=serversection.split('_')[1]
#
# Code to operate on the servers here
#

Larry Bates
s9************@yahoo.com wrote:
hi
i used ConfigParser to read a config file. I need the config file to
have identical sections. ie :

[server]
blah = "some server"
[destination]
blah = "some destination"
[end]
end= ''

[server]
blah = "some other server"
[destination]
blah = "some other destination"
[end]
end=''

and i need to check that every 'server' and 'destination' is followed
by 'end'

if i used the 'sections' method, it always show 'server' and
'destination' and 'end'. how can i iterate all the sections. ie..

for s in cfg.sections():
do something...

or is naming all the sections with different names is a better option?
thanks

Nov 4 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2033
by: Sami | last post by:
Hello, I have this problem that I need your help with : I am reading a config file that contain the following : 2004 update
1
2820
by: Paul Fi | last post by:
I have this problem with .NET remoting: my remote class is called RemoteHandler which implements an interface called IEazyRemoting which has only one method to be implemented which is my server...
3
2408
by: spacekid | last post by:
Hi there I am exposing a c# assembly as a COM component (regasm /codebase) and calling it from classic asp. When I try to call the ConfigurationSettings.AppSettings function in the c# assembly,...
8
5749
by: Martin Eyles | last post by:
Hi, I have a configuration file I made in xml which I am using to name a database server. (this way I can deploy my web page on various servers, and just change this file to make it work)....
1
1679
by: comic_rage | last post by:
Hi, I am trying to read from my application config file and keep getting null. Here is my config file My application is called SampleApp.exe
3
1608
by: Eroc | last post by:
I'm new to XML files so I'm kinda lost here. I found some example code on reading an XML file. My objective is simple. Read the whole XML file into memory. Here is part of my code: Private...
10
9412
by: Ryan | last post by:
I've created a custom configuration section that inherits (naturally) from System.Configuration.ConfigurationSection. The configuration section is working 99% fine, however I keep coming across a...
5
10322
by: alf | last post by:
Hi folks, I'm trying to read a web.config section using RoleManagerSection settings = (RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager"); and I...
1
7468
by: M Irfan | last post by:
Hello all, Recently I have started working in .NET 2.0. I am developing a web service application that references a DLL component written in C# 2.0. The component has its own config file which...
1
2240
by: vijayarl | last post by:
Hi Everyone, i have the written this logic : basically a file operation open (CONFIGFILE, "$config_file") or die; while (<CONFIGFILE>) { chomp;
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
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,...
0
7197
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...
1
6881
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...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
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...

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.