There are a lot of times when we get some important variables in Python's running process, such as a dict with a large amount of data. Also, some of the subsequent programs will use this dict, then we'd better store it locally, and then the next time you call, read the local file, import into the dictionary type, call. This eliminates the process of re-learning the dictionary. So how do you store data locally in Python?
We are using the Pickle module in Python.
As follows:
ImportPickledata1 = {' A ': [1,2.0,3,4+6j],' B ': (' String ',u ' Unicode string '),' C ':None}selfref_list = [1,2,3]selfref_list.append (selfref_list) output = open (' Data.pkl ',' WB ')# Pickle Dictionary using protocol 0.Pickle.dump (data1, Output)# Pickle The list using the highest protocol available.Pickle.dump (selfref_list, Output,-1) Output.close ()
Summary: Use Pickle.dump to store variables in the program to a local file, and then use Pickle.load to import data from a local file into a variable in the program to implement the call.
Ps:pickle incredibly is the meaning of kimchi, dump is dumping meaning, this kind of memory is easier.
In fact, the main thing is to remember the use of pickle module ~
Reference Links:
Http://www.cnblogs.com/pzxbc/archive/2012/03/18/2404715.html
How to store data locally in Python