Creating a Configuration File with ConfigParser

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Fri Jan 17 08:49:20 EST 2003


On Fri, 2003-01-17 at 12:43, Bernardo Clavijo wrote:
> Hello, everybody, I'm a newbie in python, so, you'll be reading a lot of
> idiot questions by me ;-)
> This time the question is:
> Could I create a new configuration with ConfigParser? I know I can
> change the values taken form a file, but:
> Could it create a new section and add new items?
> If you know how to do it tell me, if this couldn't be done with
> ConfigPaser tell me if there's another way.
> 

pydoc is your friend:-


m-franklin $ pydoc ConfigParser

Python Library Documentation: module ConfigParser

NAME
    ConfigParser - Configuration file parser.

FILE
    /usr/local/lib/python2.2/ConfigParser.py

DESCRIPTION
    A setup file consists of sections, lead by a "[section]" header,
    and followed by "name: value" entries, with continuations and such
in
    the style of RFC 822.

    The option values can contain format strings which refer to other
values in
    the same section, or values in a special [DEFAULT] section.

    For example:

        something: %(dir)s/whatever

<snip>
...

     |  add_section(self, section)
     |      Create a new section in the configuration.
     |
     |      Raise DuplicateSectionError if a section by the specified
name
     |      already exists.

<snip>
...
     |  sections(self)
     |      Return a list of section names, excluding [DEFAULT]
     |
     |  set(self, section, option, value)
     |      Set an option.
     |
     |  write(self, fp)
     |      Write an .ini-format representation of the configuration
state.
     |

see for full details of this module:-

http://www.python.org/doc/current/lib/module-ConfigParser.html


HTH
Martin












More information about the Python-list mailing list