【问题标题】:How to save a dictionary to properties file in python? [closed]如何将字典保存到 python 中的属性文件? [关闭]
【发布时间】:2023-01-20 21:29:55
【问题描述】:

我有一本字典

dict = {"key1":"sentence1", "key2":"sentence2"}

并想将其保存为 filename.property 文件,即

key1=sentence1
key2=sentence2

我该怎么做?

IDK 为什么这被贬低,我提供了简单的例子。

【问题讨论】:

  • 你试过什么,你被困在哪里?

标签: python json dictionary properties


【解决方案1】:

您可以简单地遍历字典中的所有元素:

my_dict = {"key1":"sentence1",  "key2":"sentence2"}

for k, v in my_dict.items():
    print(f"{k}={v}")

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 2019-11-18
    • 2016-03-29
    • 1970-01-01
    • 2013-10-12
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多