How do I use the config parser?

Larry Bates larry.bates at websafe.com
Mon May 7 09:35:26 EDT 2007


noagbodjivictor at gmail.com 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



More information about the Python-list mailing list