Python's pickle module

Source: Internet
Author: User

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

What type of data can pickle store?
    1. All Python-supported native types: Boolean, Integer, floating-point, plural, string, byte, None.
    2. Lists, tuples, dictionaries, and collections made up of any native type.
    3. Instances of functions, classes, classes
Application:
 1 #   dumps function  2 mport pickle3 data  = [  AA  , "   ,    CC   " ]    dumps converts data to a string that is known only in Python language  5 p_str = Pickle.dumps (data)  6 print  (p_str) 
7 b '
 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's pickle module

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.