How do I use the config parser?

Fuzzyman fuzzyman at gmail.com
Sat May 5 17:03:23 EDT 2007


On May 5, 8:13 pm, noagbodjivic... 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.
>

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





More information about the Python-list mailing list