# configparser 生成
import configparser
config = configparser.ConfigParser()
config[DEFUALT] = {'ServerAliveInterval':45,
'Compreassion':'yes',
'CompreassionLevel':'9'}
config['bitbucket.rog'] = {}
config['bitbucket.rog']['user'] = 'hg'
config['topsecret.server.com'] = {}
config['topsecret.server.com']['host Port'] = 52222
config['topsecret.server.com']['ForwardXll'] = 'no'
config['DEFAULT']['ForwardXll'] = 'yes'
with open('example.ini') as configfile:
config.write(configfile)
#configparser 读取
import configparser
config = configparser.ConfigParser()
config.read('example.ini') #读入文件
config.sections()
config.defaults()
config['bitbucket.org']['User']
sec = config.remove_section('bitbucket.org) #移除模块
config.write(open('i.fig','w')) #载入