Python 模块-configparser

一,新增配置文件

import configparser

config = configparser.ConfigParser()

config["DEFAULT"] = {'Server': "45", 'Comp': "yes"}

config['bitbuckket.org'] = {}

config['bitbuckket.org']['User'] = 'hg'

with open('data/example.ini', 'w') as configfile:
    config.write(configfile)
View Code

二、读取配置文件

import configparser

config = configparser.ConfigParser()
config.read('data/example.ini')
print(config.defaults())
print(config.sections())

sec = config.remove_section('bitbuckket.org')
config.write(open('data/example.ini',
                  "w"))
View Code

 

posted @ 2018-03-18 23:54  Lin_pin  阅读(105)  评论(0编辑  收藏  举报