标签:gif ict alt byte write dict 技术分享 import pickle
1 import pickle 2 3 dic={‘name‘:‘alvin‘,‘age‘:23,‘sex‘:‘male‘} 4 5 print(type(dic))#<class ‘dict‘> 6 7 j=pickle.dumps(dic) 8 print(type(j))#<class ‘bytes‘> 9 10 11 f=open(‘序列化对象_pickle‘,‘wb‘)#注意是w是写入str,wb是写入bytes,j是‘bytes‘ 12 f.write(j) #-------------------等价于pickle.dump(dic,f) 13 14 f.close() 15 #-------------------------反序列化 16 import pickle 17 f=open(‘序列化对象_pickle‘,‘rb‘) 18 19 data=pickle.loads(f.read())# 等价于data=pickle.load(f) 20 21 22 print(data[‘age‘])
标签:gif ict alt byte write dict 技术分享 import pickle
原文地址:https://www.cnblogs.com/yikedashuyikexiaocao/p/9249312.html