Python Code Learning day03-Serialization Learning pickle and JSON

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.