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. IntelliJ IDEA设置自动提示功能快捷键的方法2. .NET的基元类型包括什么及Unmanaged和Blittable类型详解3. Python-openpyxl表格读取写入的案例详解4. Java通俗易懂系列设计模式之建造者模式5. 详解Android使用CoordinatorLayout+AppBarLayout+CollapsingToolbarLayou实现手指滑动效果6. Java synchronize线程安全测试7. PHP实现rar解压读取扩展包小结8. 使用python画出逻辑斯蒂映射(logistic map)中的分叉图案例9. Python与C/C++的相互调用案例10. java实现简单贪吃蛇小游戏

网公网安备