0
点赞
收藏
分享

微信扫一扫

toml库不如tomlkit库

import toml

addr = r"d:\data\config.toml"

config = {'database': {'host': 'localhost', 'port': 5432}}

# dumps 将字典转换为TOML格式的字符串
toml_str = toml.dumps(config)

# 在字符串中添加注释
toml_str_with_comments = '# 这是一个注释\n' + toml_str

# write 将字符串写入文件
with open(addr, 'w') as f:
    f.write(toml_str_with_comments)

举报

相关推荐

0 条评论