Two modules for serialization:
JSON: Used to convert between string and Python data types
Pickle: Converting between Python-specific types and Python data types
JSON offers four features: Dumps,dump,loads,load
Pickle offers four functions: Dumps,dump,loads,load
Pickle data types that can be stored
- All Python-supported native types: Boolean, Integer, floating-point, plural, string, byte, None.
- Lists, tuples, dictionaries, and collections made up of any native type.
- Instances of functions, classes, classes
Application
1 #dumps function2 mport Pickle3data = ['AA','BB','cc'] 4 #dumps converts data into a string that is known only in Python language in a special form5P_str =pickle.dumps (data)6 Print(P_STR)7B'\x80\x03]q\x00 (x\x02\x00\x00\x00aaq\x01x\x02\x00\x00\x00bbq\x02x\x02\x00\x00\ x00ccq\x03e.
1 # 2 # loads convert pickle data to Python's structure 3 mes = 4 print Span style= "color: #000000;" > (MES) 5 [ " aa ", " bb ", " CC ]
1 # 2 # dump transforms the data into a string that is known only in Python language and writes to the file in a special form. 3 with open ( d:/tmp.pk ", " w ) as F: 4 pickle.dump (data, F)
1 # Load Function 2 # load reads data from the data file and transforms it into a python structure 3 with open ('d:/tmp.pk'R') as F: 4 data = Pickle.load (f)
Python---Pickle