Python-json&pickle Module (serialization module)

Source: Internet
Author: User

What does serialization mean?

is to store the data in memory on the hard disk.

Why do I have to put the data in memory on the hard disk?

1. The program is running, shutting down, memory data loss.

2. The next time the program starts again, read back from the hard disk, or the original format, it is very good.

3. Most of the data in memory is in the form of nested dictionaries.

What is the point of extracting the memory data?

1. Share the memory data with other people through the network.

2. You can share data across platforms and across languages. Eg:c, Java, python

#1.json Usage#serialization of DumpsImportJsondata= {'K1': 123,'K2': 345}#serialize data to a stringD =json.dumps (data)Print(d, type (d))#serialize data into a string and deposit the filef = open ('Test.json','W') Json.dump (data, F)#turn a serialized string back into a dictionaryD2 =Json.loads (d)Print(d2['K1'])#serialize data into a string and deposit the filef = open ('Test.json','R') Data2=json.load (f)Print(Data2, type (DATA2))

Note: Dump can be written multiple times, but load can only be once . The JSON deserialization error is reported.

Python-json&pickle Module (serialization module)

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.