python操作toml文件的示例代碼
更新時間:2020年11月27日 16:58:20 作者:python學習開發(fā)
這篇文章主要介紹了python操作toml文件的示例代碼,幫助大家更好的理解和學習python,感興趣的朋友可以了解下
# -*- coding: utf-8 -*-
# @Time : 2019-11-18 09:31
# @Author : cxa
# @File : toml_demo.py
# @Software: PyCharm
import toml
import os
BASE_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_data
if __name__ == '__main__':
f = FileOperation()
data = f.read()
print(data)
以上就是python操作toml文件的示例代碼的詳細內容,更多關于python操作toml文件的資料請關注腳本之家其它相關文章!
相關文章
Python畫圖常用代碼總結大全(20個畫圖代碼現(xiàn)拿現(xiàn)用)
Python是一種高級編程語言,擁有豐富的圖形庫,可以完成繪制各種類型的圖形任務,下面這篇文章主要給大家介紹了關于Python畫圖常用代碼的相關資料,文中介紹的這20個畫圖代碼可以現(xiàn)拿現(xiàn)用,需要的朋友可以參考下2023-06-06
Django框架中數(shù)據(jù)的連鎖查詢和限制返回數(shù)據(jù)的方法
這篇文章主要介紹了Django框架中數(shù)據(jù)的連鎖查詢和限制返回數(shù)據(jù)的方法,Django是Python重多高人氣框架中最為著名的一個,需要的朋友可以參考下2015-07-07
python實現(xiàn)顏色rgb和hex相互轉換的函數(shù)
這篇文章主要介紹了python實現(xiàn)顏色rgb和hex相互轉換的函數(shù),可實現(xiàn)將rgb表示的顏色轉換成hex值的功能,非常具有實用價值,需要的朋友可以參考下2015-03-03

