激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - python讀寫ini配置文件方法實例分析

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

2020-07-18 11:18不吃皮蛋 Python

這篇文章主要介紹了python讀寫ini配置文件方法,實例分析了Python針對ini配置文件的相關讀寫技巧,需要的朋友可以參考下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 黄色毛片免费看 | 国产一级免费片 | 国内成人自拍视频 | 亚洲射情 | 91av视频大全| gogo全球大胆高清人露出91 | 欧美亚洲国产一区二区三区 | 久久伊人精品视频 | 国产小视频在线 | 久久伊人国产精品 | 一级视频片 | 国产1区2区3区中文字幕 | 青青草免费观看完整版高清 | 久久精品中文字幕一区二区三区 | 免费观看视频91 | 国产成人小视频在线观看 | 日韩不卡一区二区 | 国产91精品一区二区麻豆亚洲 | 久久成人国产精品 | 国产精品中文在线 | 亚洲性综合网 | 蜜桃网站在线 | 久久精品网| 97超级碰碰人国产在线观看 | 二区三区四区 | 大胆在线日本aⅴ免费视频 永久免费毛片 | 国产亚洲精品美女久久久 | 午夜视频在线免费 | 3344永久免费 | 国产一区二区三区视频观看 | 国产黄色毛片 | 国产精品视频免费在线观看 | 一级电影免费在线观看 | 99久久精品免费视频 | 九色中文字幕 | 欧美黄色大片免费观看 | 午夜视频在线在免费 | 免费a级毛片大学生免费观看 | 国产精品久久久久免费视频 | 久久久久亚洲精品 | 免费在线观看一级片 |