Python从文件中检索数据

示例

以下代码段打开一个JSON编码的文件(替换filename为文件的实际名称),并返回存储在文件中的对象。

import json

with open(filename, 'r') as f:
    d = json.load(f)