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