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)!