专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

python读写ini配置文件方法实例分析_python

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/3/9 4:18:07       共计:3612 浏览

python读写ini配置文件方法实例分析?

代码示例:

import ConfigParser

import os

class ReadWriteConfFile:

currentDir=os.path.dirname(__file__)

filepath=currentDir+os.path.sep+"inetMsgConfigure.ini"

@staticmethod

def getConfigParser():

cf=ConfigParser.ConfigParser()

cf.read(ReadWriteConfFile.filepath)

return cf

@staticmethod

def writeConfigParser(cf):

f=open(ReadWriteConfFile.filepath,"w");

cf.write(f)

f.close();

@staticmethod

def getSectionValue(section,key):

cf=ReadWriteConfFile.getConfigParser()

return cf.get(section, key)

@staticmethod

def addSection(section):

cf=ReadWriteConfFile.getConfigParser()

allSections=cf.sections()

if section in allSections:

return

else:

cf.add_section(section)

ReadWriteConfFile.writeConfigParser(cf)

@staticmethod

def setSectionValue(section,key,value):

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')

print x

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:怎样检查声卡驱动是不是坏了_服务器 | ·下一条:怎么让minecraft做到全地图大海_服务器

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有