【发布时间】:2021-07-30 10:58:21
【问题描述】:
每当我的代码运行时,我都会尝试用新名称保存字典。
代码:
import json
dictionary = {'happy':1,'sad':2,'angry':3}
count = 0
with open('/home/hamza/Desktop/time_duration_file'+str(count)+'.json','w') as data:
file = json.dump(dictionary,data)
count+=1
每当我的代码运行时,上面的代码都会覆盖字典。每当我的代码运行时,我都想每次用新名称保存字典。
预期输出:
Code Runs (1)
Code Runs (2)
.
.
输出应该是:
time_duration_file1.json
time_duration_file2.json
.
.
【问题讨论】:
标签: python json dictionary