【发布时间】:2023-01-12 02:28:26
【问题描述】:
我想将我的字典转换为 yaml,其中键在不带引号的情况下呈现,但值用单引号引起来。
我找到了几种将键和值都包含在单引号中的解决方案,但这不是我想要的。您可以在下面看到一个示例脚本:
import yaml
theDict = {'this' : {'is': 'the', 'main': 12,'problem':'see?' }}
print(yaml.dump(theDict, default_flow_style=False, sort_keys=False))
这将输出:
this:
is: the
main: 12
problem: see?
但是我想要:
this:
is: 'the'
main: '12'
problem: 'see?'
【问题讨论】: