11. Pickle serialization

Source: Internet
Author: User


Common Syntax: dump: Installs the object status in the current memory on the hard disk file. Common Syntax: load: Import objects in disk files to memory Exercises: Store account information in the dictionary, use pickle dump to the file, and load to modify the dictionary
  1. [[email protected] python_scripts]# cat 15pickle_dump.py #!/usr/bin/pythonimport pickleaccount_info={        ‘01‘:[‘mima‘,15000,15000],        ‘02‘:[‘mima‘,2000,2000]}f=open(‘acc.txt‘,‘wb‘)pickle.dump(account_info,f)f.close()

  1. [[email protected] python_scripts]# cat 16pickle_load.py #!/usr/bin/pythonimport picklef=open(‘acc.txt‘,‘r‘)info=pickle.load(f)f.close()info[‘02‘][1]=20000f=open(‘acc.txt‘,‘w‘)pickle.dump(info,f)f.close()

[[Email protected] python_scripts, draw 50 RMB ['mima', 1950,200 0] [[[email protected] python_scripts] # Python 16pickle_load.py -- spend 50 RMB ['mim ', 1900,200 0] [[email protected] python_scripts] # Python 16pickle_load.py -- spend 50 yuan ['mim ', 1850,200 0] [[email protected] python_scripts] # Python 16pickle_load.py -- spend 50 yuan ['mim', 1800,200 0]

11. Pickle serialization

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.