python知识整理

文件存储

字典内容写入json文件

1
2
3
4
5
6
7
8
9
10
11
12
13
test_dict = {
'version': "1.0",
'results': video,
'explain': {
'used': True,
'details': "this is for josn test",
}
}

json_str = json.dumps(test_dict, indent=4) # 有缩进,不指定indent为无缩进
with open('test_data.json', 'w') as json_file:
json_file.write(json_str)