Re: How do I use the config parser?

2007-05-07 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Hi,
 I need a specific example. I have seen the docs, but I don't all the
 stuffs there.
 
 So basically, I need my config file to be created and read by my
 script.
 
 Here is a snippet
 
 # read old actions
 from ConfigParser import ConfigParser
 
 fp = open(makepath('App\qt_actions.conf'))
 configdict = ConfigParser()
 configdict.readfp(fp)
 
 
 Now I want to know how to read a section, a section attribute's value,
 and to write thoses back after reading.
 
 Thanks
 

The best place to start is always:

import ConfigParser
help(ConfigParser)


Example:

section='INIT'
option='logfile'

logfile=configdict.get(section, option)

most of the methods are self explanitory.

-Larry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I use the config parser?

2007-05-05 Thread Rob Williscroft
 wrote in news:[EMAIL PROTECTED] in 
comp.lang.python:

 Hi,
 I need a specific example. I have seen the docs, but I don't all the
 stuffs there.
 

 from ConfigParser import ConfigParser

 
 Now I want to know how to read a section, a section attribute's value,
 and to write thoses back after reading.
 

ConfigParser is derived from RawConfigParser, so you need
to look at RawConfigParser's docs here:

http://docs.python.org/lib/RawConfigParser-objects.html


Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I use the config parser?

2007-05-05 Thread Fuzzyman
On May 5, 8:13 pm, [EMAIL PROTECTED] wrote:
 Hi,
 I need a specific example. I have seen the docs, but I don't all the
 stuffs there.

 So basically, I need my config file to be created and read by my
 script.

 Here is a snippet

 # read old actions
 from ConfigParser import ConfigParser

 fp = open(makepath('App\qt_actions.conf'))
 configdict = ConfigParser()
 configdict.readfp(fp)

 Now I want to know how to read a section, a section attribute's value,
 and to write thoses back after reading.


You could do it simply with ConfigObj ( 
http://www.voidspace.org.uk/python/configobj.html
):

from configobj import ConfigObj

config = ConfigObj(filename)
section = config['Section Name']
value = section['value']



section['value'] = newValue
config.write()

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml


 Thanks


-- 
http://mail.python.org/mailman/listinfo/python-list