示例1:讲一个列表以二进制形式保存
#!/usr/bin/python
import pickle
my_list = [12,3.14,'chenzhitao',[1,2,3]]
pickle_file = open('my_list.pkl','wb')
pickle.dump(my_list,pickle_file)
pickle_file.close()
示例2:将二进制文件读出来
#!/usr/bin/python
import pickle
pickle_file = open('my_list.pkl','rb')
my_list = pickle.load(pickle_file)
print(my_list)
网友评论