国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python讀寫ini配置文件方法實例分析

2019-11-25 17:14:50
字體:
來源:轉載
供稿:網友

本文實例講述了python讀寫ini配置文件方法。分享給大家供大家參考。具體實現方法如下:

import ConfigParserimport osclass 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

希望本文所述對大家的Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衡山县| 宣城市| 新巴尔虎左旗| 敦煌市| 会理县| 柏乡县| 正定县| 鱼台县| 平罗县| 改则县| 潢川县| 凤山县| 哈巴河县| 黄山市| 常山县| 丰城市| 大化| 天长市| 嘉兴市| 革吉县| 乌海市| 全椒县| 崇文区| 庄河市| 葫芦岛市| 察隅县| 浦东新区| 郸城县| 布尔津县| 宁乡县| 铁岭县| 革吉县| 宜昌市| 裕民县| 泰顺县| 柳河县| 山东| 普兰县| 临海市| 台湾省| 崇阳县|