内容提要:
1: pickle的主要作用
pickle主要用于python 于python 之间进行文件传出,网络传输
他同json 一样也是有4个函数
pickle.dumps(iterable) #内容转化成bates
pickle.loads(iterable) #bates 转化成人看的
pickle.dump(dic,句柄) # 用于存文件
pickle.load(句柄) #用于读取文件
2:pickle 将内容转化成bates 类型
# dic = {'name': "太白金星", # 'hobby_list': ['戒烟', '烫不了头', '戒酒'], # 'age': 18, # 'money': '1个亿'} # s1 =pickle.dumps(dic) # # print(s1) #转化成Rb bate 字节类型,不过仅仅支持python 通信
3:pickle 将bates 转化成人看的内容
# dic2 =pickle.loads(s1) # print(dic2)
4:pickle 写入文件
# with open('p1.pkl',mode='wb') as f1: # pickle.dump(dic,f1)
5: pickle 读取文件
# with open('p1.pkl',mode='rb') as f2: # ret =pickle.load(f2) # print(ret)
6:pickle 多读多写
# dic1 = {'name': '春哥'} # dic2 = {'name': '子伍'} # dic3 = {'name': '王子'} # with open('p2.pkl',mode='wb') as f3: # pickle.dump(dic1,f3) # pickle.dump(dic2,f3) # pickle.dump(dic3,f3) # with open('p2.pkl',mode='rb') as f4: # ret1=pickle.load(f4) # ret2=pickle.load(f4) # ret3=pickle.load(f4) # print(ret1) # print(ret2) # print(ret3)