把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.