"Python standard library module four" JSON module and Pickle module learning

Source: Internet
Author: User

JSON module

There was an eval function that could extract a corresponding data type from a string, such as "{" "Name": "Zhangsan"} "to extract a dictionary." JSON modules can do the same thing, but more powerful, Eval can only recognize the data structure of the Python language. JSON can recognize multi-language data structures

    • Import of modules
      Import JSON
    • Encapsulates a data type in JSON format (string) with dumps
      DIC = {"name":"codescrew"= json.dumps (DIC)
    • Restores the JSON format to the original data type loads
      DIC = Json.loads (DIC_STR)
    • Encapsulate the data type in JSON format and write to the file using the dump
      Dic_str = Json.dump (dic,filename)
    • Read the JSON from the file and restore it, using the load
      Json.load (filename)
Pickle Module

The use of pickle is exactly the same as the JSON module. The difference is that JSON is finally encapsulated in a string form, and pickle encapsulates the serialized object (byte type). Pickle modules can encapsulate more data types (functions, classes can also be encapsulated)

"Python standard library module four" JSON module and Pickle module learning

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.