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. SpringBoot2整合Ehcache组件实现轻量级缓存管理2. Django def clean()函数对表单中的数据进行验证操作3. django中嵌套的try-except实例4. 浅谈vue实现双向事件绑定v-model的原理5. Android WebView通过动态的修改js去拦截post请求参数实例6. Admin - SpringBoot + Maven 多启动环境配置实例详解7. 如何用python写个模板引擎8. SpringBoot 启动方法run()源码解析9. spring boot集成mongodb的增删改查的示例代码10. Django结合使用Scrapy爬取数据入库的方法示例