Getting Started with Python--17--pickle

Source: Internet
Author: User

Pickle module, the actual use is also very simple, single, mainly used for saving lists (list), Ganso (Tuple), Dictionary (dictionary)

Of course, it must be a large list, a dictionary or something, thousands of lines of dictionaries, lists, to highlight its useful

Instance

Import Pickle
my_list=[' 123 ', ' 3.14 ', ' ee '] #创建一个list
Pickle_file=open (' My_pickle1 ', ' WB ') #以二进制的方式打开文件
Pickle.dump (My_list,pickle_file) #使用pickle包中的dump函数把列表中的数据放入文件中
Pickle_file.close () #关闭文件

Pickle_file=open (' My_pickle1 ', ' RB ') #再以二进制的形式打开文件
My_list2=pickle.load (Pickle_file) #使用pickle包中的load函数把数据赋值给my_list2
Print (MY_LIST2)

Getting Started with Python--17--pickle

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.