example.conf

[DEFAULT]
in_default = 'an option value in default'
conn_str = %(dbn)s://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s
dbn = mysql
user = root
host = localhost
port = 3306
[db1]
user = aaa
pw=ppp
db=example
[db2]
host = 192.168.0.110
pw = www
db = example
[section1]
in_default = 'an option value in section1'

read_ini.py

import ConfigParser
conf = ConfigParser.ConfigParser()
conf.read('example.conf')
print conf.get('section1','in_default')

print conf.get('db1','conn_str')
print conf.get('db2','conn_str')

results matching ""

    No results matching ""