【发布时间】:2016-02-21 16:58:09
【问题描述】:
我创建了一个文件,其中包含我正在使用的字典列表。不幸的是,我不确定如何以相同的格式将该文件重新导入 python。
我最初将文件写成 JSON 和文本,如下所示:
d = list_of_dics
jsonarray = json.dumps(d)
with open('list_of_dics.txt', 'w') as outfile:
json.dump(jsonarray, outfile)
with open('list_of_dics.json', 'w') as outfile:
json.dump(jsonarray, outfile)
谁能建议一种将这些以相同格式(即字典列表)重新导入 python 的方法?
【问题讨论】:
-
这里只是一个猜测,但通常如果库为 json 函数提供“编码”(在这种情况下为
.dump),它也会提供来自 json 函数的“解码”。你检查过文档吗?
标签: python dictionary