Python JSON & Pickle, shelve module

Source: Internet
Author: User

Json

    • Conversions between data types for strings and Python
    • Four functions
      • Dumps
      • Dump
      • Loads
      • Load

Pickle

    • Conversion for Python-specific types and Python data types
    • Four functions
      • Dumps
      • Dump
      • Loads
      • Load

Shelve

  • K,v is a simple module that persists memory data through a file, and can persist any Python data format that pickle can support
  • 1 #!/user/bin/python2 #-*-coding:utf-8-*-3 Importshelve4 5D = Shelve.open ('shelve_test')#Open the current script (the name in Open is the name of the current script)6 7 #info = {' age ': ' Job ': ' It '}8 #9 #name=[' Alex ', ' rain ', ' Test ']Ten #d[' name ' = name # The persistence list generates a file in the current directory that stores the information in the name. One #d[' info ' = info # persistence dictionary, generates a file in the current directory to store information in info. A #altogether three files were generated, shelve_test.bak; slelve_test.dat; shelve_test.dir. -  -  the #The contents of the name and info can be obtained by reading the contents of the generated file. - Print(D.get ('name')) - Print(D.get ('Info'))

Python JSON & Pickle, shelve 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.