【发布时间】:2020-05-19 15:25:30
【问题描述】:
我有一个 python 字典{'A': '1', 'B': '2', 'C': '3'}。我想将此字典写入文件。我就是这样做的;
test_dict = {'A': '1', 'B': '2', 'C': '3'}
f = open("dict.txt", "w")
f.write(str(test_dict))
f.close()
但是,我希望文本文件看起来像这样;
{
'A': '1',
'B': '2',
'C': '3',
}
写入文本文件时如何添加换行符? 我正在使用 python 3.7
【问题讨论】:
标签: python python-3.x writefile