把Python dict用JSON格式存到硬盘

如果需要保存Python运行中的某个dict对象,或者从硬盘里的JSON读进内存,可以用下面命令

import json

# Serialize data into file:
json.dump( data, open( "file_name.json", 'w' ) )

# Read data from file:
data = json.load( open( "file_name.json" ) )

Leave a Comment

Your email address will not be published.