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

定制建站费用3500元

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

成都品牌网站建设

品牌网站建设费用6000元

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

成都商城网站建设

商城网站建设费用8000元

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

成都微信网站建设

手机微信网站建站3000元

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

建站知识

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

pythonconfigParser模块

configParser 模块用于操作配置文件
配置文件(INI文件)由节(section)、键、值组成
1、config=ConfigParser.ConfigParser() 创建ConfigParser实例
2、config.sections() 返回配置文件中节序列
3、config.options(section) 返回某个项目中的所有键的序列
4、config.get(section,option) 返回section节中,option的键值
5、config.add_section(str) 添加一个配置文件节点(str)
6、config.set(section,option,val) 设置section节点中,键名为option的值(val)
7、config.read(filename) 读取配置文件
8、config.write(obj_file) 写入配置文件
9、config.get() 返回文本 config.getint()返回整数
10、config.remove_option( section, option)
11、config.remove_section( section)
案例:
import ConfigParser
import os
class ReadWriteConfFile:
currentDir=os.path.dirname(file) filepath=currentDir+os.path.sep+"inetMsgConfigure.ini"
@staticmethod
br/>filepath=currentDir+os.path.sep+"inetMsgConfigure.ini"
@staticmethod
cf=ConfigParser.ConfigParser()
cf.read(ReadWriteConfFile.filepath)
return cf@staticmethod
br/>@staticmethod
f=open(ReadWriteConfFile.filepath,"w"); cf.write(f)
f.close();
@staticmethod
br/>cf.write(f)
f.close();
@staticmethod
cf=ReadWriteConfFile.getConfigParser()
return cf.get(section, key)@staticmethod
br/>@staticmethod
cf=ReadWriteConfFile.getConfigParser()
allSections=cf.sections()
if section in allSections:return
else:
cf.add_section(section)
ReadWriteConfFile.writeConfigParser(cf)
@staticmethod
br/>return
else:
cf.add_section(section)
ReadWriteConfFile.writeConfigParser(cf)
@staticmethod
cf=ReadWriteConfFile.getConfigParser()
cf.set(section, key, value)
ReadWriteConfFile.writeConfigParser(cf)
if name== 'main':
ReadWriteConfFile.addSection( 'messages')
ReadWriteConfFile.setSectionValue( 'messages','name','sophia')
x=ReadWriteConfFile.getSectionValue( 'messages','1000')

创新互联公司是专业的亚东网站建设公司,亚东接单;提供成都网站制作、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行亚东网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!


网站栏目:pythonconfigParser模块
URL分享:http://bjjierui.cn/article/iiidpi.html

其他资讯