Creating a Configuration File with ConfigParser

Martin Franklin mfranklin1 at
Fri Jan 17 14:49:20 CET 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

    ConfigParser - Configuration file parser.


    A setup file consists of sections, lead by a "[section]" header,
    and followed by "name: value" entries, with continuations and such
    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


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

     |  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

see for full details of this module:-


More information about the Python-list mailing list