网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

configparser模块

生成文件

import configparser

专注于为中小企业提供成都网站设计、成都网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业江城免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

config = configparser.ConfigParser()
#在DEFAULT节点下添加,类似字典的key和value
config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9'}

config['bitbucket.org'] = {"alex":33}
config['bitbucket.org']['User'] = 'hg'

config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022' # mutates the parser
topsecret['ForwardX11'] = 'no' # same here

config['DEFAULT']['ForwardX11'] = 'yes' #在在DEFAULT节点下添加key为'ForwardX11,value为yes的数据
with open('example.ini', 'w') as configfile:
config.write(configfile)

[DEFAULT] 创建文件的内容

#serveraliveinterval = 45
#compression = yes
#compressionlevel = 9
#forwardx11 = yes

#[bitbucket.org]
#alex = 33
#user = hg

#[topsecret.server.com]
#host port = 50022
#forwardx11 = no

configparser文件读取写入

import configparser

conf=configparser.ConfigParser()
conf.read("example.ini")
print(conf.sections())#打印节点(除了“DEFAULT”以外的节点)
print(conf["bitbucket.org"]["user"])
print(conf.defaults())#打印[DEFAULT]

#删除后,创建新文件写入
#sec = conf.remove_section('bitbucket.org')
#conf .write(open('exmple.cfg', "w"))

#删除后,覆盖原文件
#sec = conf.remove_section('bitbucket.org')
#conf .write(open('exmple.ini', "w"))


网页标题:configparser模块
文章起源:http://bjjierui.cn/article/peidoe.html

其他资讯