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文件的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Python2.6版本pip安裝步驟解析2. python公司內(nèi)項(xiàng)目對(duì)接釘釘審批流程的實(shí)現(xiàn)3. python中Ansible模塊的Playbook的具體使用4. Python自動(dòng)化之定位方法大殺器xpath5. Python本地及虛擬解釋器配置過(guò)程解析6. Python 利用flask搭建一個(gè)共享服務(wù)器的步驟7. 基于python實(shí)現(xiàn)matlab filter函數(shù)過(guò)程詳解8. Python中Anaconda3 安裝gdal庫(kù)的方法9. python自動(dòng)化測(cè)試三部曲之request+django實(shí)現(xiàn)接口測(cè)試10. Python importlib模塊重載使用方法詳解
