example on how to use configparser in python?

Olmy olmy at thistledown.org
Mon Jul 17 10:24:14 EDT 2000


> Does anyone have that?

Hello,

assuming you have a config file called test.conf and it contains the 
following:

[DEFAULT]

name = pythontest
path = /tmp/test


then you should be able to use the following quickie test script:

from ConfigParser import *

configdict = ConfigParser()
configdict.read('test.conf')

print configdict.defaults().keys()
print configdict.defaults()['path']

path = configdict.defaults()['path']

print path


that should give you a quick idea of how to load your config file 
in ConfigParser's dictionary format.

See the following URL for the reference documentation on what else 
you can do with ConfigParser:

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

Pay special attention on how to handle RFC822 sections and how to handle 
the "%" expansions.

Hope this helps.

jeff





More information about the Python-list mailing list