python操作toml文件的示例代碼
# -*- coding: utf-8 -*-# @Time : 2019-11-18 09:31# @Author : cxa# @File : toml_demo.py# @Software: PyCharmimport tomlimport osBASE_DIR = os.path.dirname(os.path.abspath(__file__))class FileOperation: def __init__(self): self.dic = dict() self.toml_file_path = os.path.join(BASE_DIR, 'config.toml') def __add__(self, other): self.dic.update(self.other) return self.dic def write(self): mysql_dic = {'user': 'root', 'password': 'Aa1234'} mysql2_dic = {'user1': 'root', 'password2': 'Aa1234'} mysql_dic.update(mysql2_dic) with open(self.toml_file_path, 'w', encoding='utf-8') as fs: toml.dump(mysql_dic, fs) def read(self): with open(self.toml_file_path, 'r', encoding='utf-8') as fs: t_data = toml.load(fs) return t_dataif __name__ == ’__main__’: f = FileOperation() data = f.read() print(data)
以上就是python操作toml文件的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于python操作toml文件的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能2. PHP循環(huán)與分支知識點(diǎn)梳理3. jsp EL表達(dá)式詳解4. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法5. Ajax請求超時(shí)與網(wǎng)絡(luò)異常處理圖文詳解6. jsp cookie+session實(shí)現(xiàn)簡易自動(dòng)登錄7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法8. JavaWeb Servlet中url-pattern的使用9. JSP之表單提交get和post的區(qū)別詳解及實(shí)例10. chat.asp聊天程序的編寫方法
