[Python] Kimchi storage (the pickle)

  For save text, if you want to save data like lists, dictionaries, and even when the instance of the class, ordinary file operations will be very complicated, if these strings into a text file written to save, put this process in turn read It would take the trouble anomaly, therefore provides a standard module python pickle.

  pickle module translated into pickles, python use this module, you can very easily lists, dictionaries such complex data type is stored as a file, all the python object into a binary form of storage, a process known as pickling, converted back to binary form process object to unpicking.

  

# Kimchi storage 
Import pickle 
my_list = [123, 456,, ' makes big head ' , ' chicken you're so beautiful ' ] 
pickle_file = Open ( ' E: \\ my_list.pk1 ' , ' wb ' ) 
the pickle.dump (my_list, pickle_file) 
pickle_file. close ()
#泡菜读取
import pickle
pickle_file=open("E:\\my_list.pk1","rb")
my_list=pickle.load(pickle_file)
print(my_list)

 

Guess you like

Origin www.cnblogs.com/zlc364624/p/11599773.html