python讀寫ini配置文件方法實(shí)例分析
本文實(shí)例講述了python讀寫ini配置文件方法。分享給大家供大家參考。具體實(shí)現(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
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
pyppeteer執(zhí)行js繞過webdriver監(jiān)測方法上
這篇文章主要為大家介紹了pyppeteer執(zhí)行js繞過webdriver監(jiān)測方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-04-04圖解Python中淺拷貝copy()和深拷貝deepcopy()的區(qū)別
這篇文章主要介紹了Python中淺拷貝copy()和深拷貝deepcopy()的區(qū)別,淺拷貝和深拷貝想必大家在學(xué)習(xí)中遇到很多次,這也是面試中常常被問到的問題,本文就帶你詳細(xì)了解一下2023-05-05如何使用Python實(shí)現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換
這篇文章主要介紹了用Python實(shí)現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-10-10Python爬蟲原理與基本請(qǐng)求庫urllib詳解
這篇文章主要介紹了Python爬蟲原理與基本請(qǐng)求庫urllib詳解,爬蟲就是通過模擬瀏覽器,按照一定的規(guī)則,自動(dòng)、大批量的獲取網(wǎng)絡(luò)資源,包括文本、圖片、鏈接、音頻、視頻等等,需要的朋友可以參考下2023-07-07Python數(shù)據(jù)分析之使用matplotlib繪制折線圖、柱狀圖和柱線混合圖
matplotlib是python的一個(gè)模塊,用于繪制各種圖形,今天介紹一下折線圖的繪制,下面這篇文章主要給大家介紹了關(guān)于Python數(shù)據(jù)分析之使用matplotlib繪制折線圖、柱狀圖和柱線混合圖的相關(guān)資料,需要的朋友可以參考下2022-05-05pytest多進(jìn)程或多線程執(zhí)行測試實(shí)例
這篇文章介紹了pytest多進(jìn)程或多線程執(zhí)行測試的實(shí)例,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07