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文件的示例代碼的詳細內容,更多關于python操作toml文件的資料請關注好吧啦網其它相關文章!
相關文章:
1. php測試程序運行速度和頁面執行速度的代碼2. ASP中常用的22個FSO文件操作函數整理3. 三個不常見的 HTML5 實用新特性簡介4. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報錯問題分析5. ASP調用WebService轉化成JSON數據,附json.min.asp6. SharePoint Server 2019新特性介紹7. React+umi+typeScript創建項目的過程8. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁9. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析10. php網絡安全中命令執行漏洞的產生及本質探究
