最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2015年06月30日 16:58:30   作者:不吃皮蛋  
這篇文章主要介紹了python讀寫ini配置文件方法,實例分析了Python針對ini配置文件的相關(guān)讀寫技巧,需要的朋友可以參考下

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

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

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

相關(guān)文章

最新評論

武胜县| 长泰县| 民县| 彭州市| 高邮市| 兴安盟| 东兴市| 微博| 莱芜市| 盈江县| 丁青县| 祥云县| 建瓯市| 东台市| 阳朔县| 遂平县| 洱源县| 凤台县| 凤庆县| 卫辉市| 古浪县| 贵南县| 滦平县| 阜阳市| 陈巴尔虎旗| 塔河县| 洛浦县| 浮山县| 牟定县| 个旧市| 贵阳市| 郎溪县| 纳雍县| 麦盖提县| 海伦市| 通许县| 东山县| 泸水县| 兴宁市| 梁山县| 铁力市|