Python 模块-configparser

mac2022-06-30  24

一,新增配置文件

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

 

转载于:https://www.cnblogs.com/Linc2010/p/8598390.html

最新回复(0)