Day5 common modules json and pickle

Source: Internet
Author: User

JSON and Pickle

JSON and pickle are used for string serialization and deserialization, and when we store and use it, we often save the list in a file, and we want to read it as a list when we read it. You need to use JSON and pickle. JSON is a support for all interfaces, and Pickle is Python's own built-in interface.

Two modules for serialization

(1) JSON for converting between string and Python data types

(2) Pickle for conversion between Python-specific types and Python data types

The JSON module provides four functions: dumps, dump, loads, load

The Pickle module provides four functions: dumps, dump, loads, load

Methods of the JSON module:

(1) Dump ()

def dump (obj, FP, Skipkeys=false, Ensure_ascii=true, Check_circular=true,
Allow_nan=true, Cls=none, Indent=none, Separators=none,
Default=none, Sort_keys=false, **kw):
" "" Serialize "' obj ' ' as a JSON f ormatted stream to ' FP ' (a

Dump (OBJ,FP) is the writing of information to a file, and dump () is the first to convert obj into a string format, file-aware content, and then write to the file.

Day5 common modules json and pickle

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.