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)
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6