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中request的3個基礎(chǔ)實(shí)踐2. Django程序的優(yōu)化技巧3. XML入門的常見問題(一)4. IntelliJ IDEA 統(tǒng)一設(shè)置編碼為utf-8編碼的實(shí)現(xiàn)5. jsp EL表達(dá)式詳解6. Django ORM實(shí)現(xiàn)按天獲取數(shù)據(jù)去重求和例子7. chat.asp聊天程序的編寫方法8. Python多線程操作之互斥鎖、遞歸鎖、信號量、事件實(shí)例詳解9. idea設(shè)置自動導(dǎo)入依賴的方法步驟10. 怎樣才能用js生成xmldom對象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?
