#!/usr/bin/env python#Coding:utf8ImportPickle,jsonImportDatetimedic1= {'name':'Alex', ' Age': 44, 'born':d Atetime.datetime.now ()}#If this is more complex, JSON cannot be parsed, and with pick, you can#memory data is stored, reused, and can be pickle serializedF= File ("D:/TEST.PKL","W") Pickle.dump (dic1,f)#writing data to a filef.close ()#deserializationf = File ("D:/TEST.PKL") Data=pickle.load (f)Print '----->', Dataf.close ()
#json in a wayf = File ("D:/TESTJSON.PKL","W") Json.dump (dic1,f) f.close () F= File ("D:/TESTJSON.PKL") Data=json.load (f)Print '------>', Dataf.close ()
The above is just the overlay of the code, the point to note is those
When using the JSON module, if the data is more complex, it will produce abnormal error, when using pickle is not the problem. See Oldboy-python the third day of the tenth issue.
Python Code Learning day03-Serialization Learning pickle and JSON