python操作toml文件的示例代码
更新时间:2020年11月27日 16:58:20 作者:python学习开发
这篇文章主要介绍了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的Django框架使用
这篇文章主要介绍了以一个投票程序的实例来讲解Python的Django框架使用,Django是Python世界中人气最高的MVC框架,需要的朋友可以参考下2016-02-02pytest解读fixture有效性及跨文件共享fixtures
这篇文章主要为大家介绍了pytest官方文档fixture有效性及跨文件共享fixtures的解读,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-06-06python中使用sys模板和logging模块获取行号和函数名的方法
这篇文章主要介绍了python中使用sys模板和logging模块获取行号和函数名的方法,需要的朋友可以参考下2014-04-04
最新评论