Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
reading a config file
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
s99999999s2...@yahoo.com  
View profile  
 More options Nov 3 2005, 10:02 pm
Newsgroups: comp.lang.python
From: s99999999s2...@yahoo.com
Date: 3 Nov 2005 19:02:00 -0800
Subject: 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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Bates  
View profile  
 More options Nov 4 2005, 9:47 am
Newsgroups: comp.lang.python
From: Larry Bates <larry.ba...@websafe.com>
Date: Fri, 04 Nov 2005 08:47:38 -0600
Local: Fri, Nov 4 2005 9:47 am
Subject: Re: reading a config file
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google