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. Android打包篇:Android Studio將代碼打包成jar包教程2. Python使用urlretrieve實現直接遠程下載圖片的示例代碼3. SpringBoot+TestNG單元測試的實現4. Springboot 全局日期格式化處理的實現5. vue實現web在線聊天功能6. 解決Android Studio 格式化 Format代碼快捷鍵問題7. 完美解決vue 中多個echarts圖表自適應的問題8. JavaScript實現頁面動態驗證碼的實現示例9. Java使用Tesseract-Ocr識別數字10. JavaEE SpringMyBatis是什么? 它和Hibernate的區別及如何配置MyBatis
