python讀寫ini配置文件方法實例分析
更新時間:2015年06月30日 16:58:30 作者:不吃皮蛋
這篇文章主要介紹了python讀寫ini配置文件方法,實例分析了Python針對ini配置文件的相關讀寫技巧,需要的朋友可以參考下
本文實例講述了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程序設計有所幫助。
相關文章
pyppeteer執(zhí)行js繞過webdriver監(jiān)測方法上
這篇文章主要為大家介紹了pyppeteer執(zhí)行js繞過webdriver監(jiān)測方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪2022-04-04圖解Python中淺拷貝copy()和深拷貝deepcopy()的區(qū)別
這篇文章主要介紹了Python中淺拷貝copy()和深拷貝deepcopy()的區(qū)別,淺拷貝和深拷貝想必大家在學習中遇到很多次,這也是面試中常常被問到的問題,本文就帶你詳細了解一下2023-05-05如何使用Python實現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換
這篇文章主要介紹了用Python實現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-10-10Python數(shù)據(jù)分析之使用matplotlib繪制折線圖、柱狀圖和柱線混合圖
matplotlib是python的一個模塊,用于繪制各種圖形,今天介紹一下折線圖的繪制,下面這篇文章主要給大家介紹了關于Python數(shù)據(jù)分析之使用matplotlib繪制折線圖、柱狀圖和柱線混合圖的相關資料,需要的朋友可以參考下2022-05-05