首页 > 代码库 > ConfigParser 实例 01

ConfigParser 实例 01

# -*- coding: utf-8 -*-
import ConfigParser
config = ConfigParser.ConfigParser()
config.readfp(open(‘ixamail.ini‘))
a = config.get("host","smtp_server")
print a
config.add_section("book")
config.set("book", "title", "the python standard library")
config.set("book", "author", "fredrik lundh")

config.add_section("ematter")
config.set("ematter", "pages", 250)

# write to file
config.write(open(‘1.ini‘, "w"))

 

config.read(‘1.ini‘)

a = config.add_section("md5")

config.set("md5", "value", "1234")

config.write(open(‘1.ini‘, "r+"))