python pickle

复制代码
 1 >>> import pickle
 2 >>> m_list=['1',2,'asa']
 3 >>> m_list
 4 ['1', 2, 'asa']
 5 >>> m_file=open('my_file.pkl','wb')
 6 >>> pickle.dump(m_list,m_file)
 7 >>> pickle.close()
 8 
 9 Traceback (most recent call last):
10   File "<pyshell#16>", line 1, in <module>
11     pickle.close()
12 AttributeError: 'module' object has no attribute 'close'
13 >>> my_file.close()
14 
15 Traceback (most recent call last):
16   File "<pyshell#17>", line 1, in <module>
17     my_file.close()
18 NameError: name 'my_file' is not defined
19 >>> m_file.close()
20 >>> m_file=open('my_file.pkl','rb')
21 >>> m_list2=pickle.load(m_file)
22 >>> print (m_list2)
23 ['1', 2, 'asa']
24 >>> 
复制代码
原文地址:https://www.cnblogs.com/wangsicongde/p/7599149.html