【发布时间】:2014-02-22 13:21:45
【问题描述】:
import json
def json_serialize(name, ftype, path):
prof_info = []
prof_info.append({
'profile_name': name,
'filter_type': ftype
})
with open(path, "w") as f:
json.dumps({'profile_info': prof_info}, f)
json_serialize(profile_name, filter_type, "/home/file.json")
上述代码不会将数据转储到“file.json”文件中。
当我在json.dumps() 之前写print 时,数据就会打印在屏幕上。
但它不会被转储到文件中。
文件已创建,但在打开它(使用记事本)时,什么也没有。 为什么?
如何纠正?
【问题讨论】:
标签: json python-2.7