import ConfigParser
//实例化
cf = ConfigPraser.ConfigPraser()
cf.read("配置文件")
//获取所有sections。也就是将配置文件中所有“[ ]”读取到列表中
s= cf.sections()
//获取指定section 的options。即将配置文件某个section 内key 读取到列表中
o = cf.options("db")
//获取指定section 的配置信息
v = cf.items("db")
//按照类型读取指定section的option 信息 getfloat getboolean getint等
db_host = cf.get("db","db_host")
db_port = cf.getint("db","db_port")
//设置某个option 的值
cf.set("db","db_pass","test")
cf.write(open("test.conf"),"w"))
//添加一个section
cf.add_section('add')
cf.set('add','addtest1','testadd')
cf.write(open("test.conf","w"))
//移除section 或者option
cf.remove_option('add','addtest1')
cf.remove_section('add')
cf.write(open("test.conf", "w"))