python pickle

时间:2023-09-20 13:40:56
 >>> import pickle
>>> m_list=['',2,'asa']
>>> m_list
['', 2, 'asa']
>>> m_file=open('my_file.pkl','wb')
>>> pickle.dump(m_list,m_file)
>>> pickle.close() Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
pickle.close()
AttributeError: 'module' object has no attribute 'close'
>>> my_file.close() Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
my_file.close()
NameError: name 'my_file' is not defined
>>> m_file.close()
>>> m_file=open('my_file.pkl','rb')
>>> m_list2=pickle.load(m_file)
>>> print (m_list2)
['', 2, 'asa']
>>>