Python 0 Basic Getting Started data permanent storage

Source: Internet
Author: User
In previous studies, when we needed to store the data in the program, we generally used lists, tuples, and so on, or used the files mentioned in the previous blog, this blog introduces a method of permanent data storage--pickle module
Because it is relatively simple, it is directly on the code
The main use is the dump and load functions in pickle.

Import  picklemy_list=[123,456, "Little Turtle", [' another list ']] #以二进制的方式写入pickle_file =open (' e:\\my_list.pkl ', ' WB ') # Write data to a file with dump# the first parameter is the data to be written, the second is the file to be written to Pickle.dump (My_list,pickle_file) #写完以后别忘记将文件关闭, otherwise it will be stored in the # buffer, and will disappear after the power loss pickle _file.close () #到这里就将序列的数据存储到了文件里面 # reads the contents of the file # operations on the file first obtain the object Pickle_file=open ("E://my_list.pkl", "RB") of the file #将pickle_ Data in file is loaded into the list my_list2=pickle.load (pickle_file) print (MY_LIST2)

The above is the Python 0 basic introduction to the data of the permanent storage content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.