pickle模块 和json模块

pickle和json序列号

json模块是所有语言通用的,可以用来把一些数据转成字符串存储在文件中

import json
l=[1,2,3]
with open('t3',mode='w',encoding='utf-8')as f:
    print(json.dump(l,f ))
import json
l=[1,2,3]
with open('t3',mode='r',encoding='utf-8')as f:
    print(json.load(f))
import pickle
l=[1,2,3]
with open('t4','wb')as f:
    pickle.dump(l,f)
import pickle
l=[1,2,3]
with open('t4','rb')as f:
    print(pickle.load(f))

上述代码描述了将对象转换成字符串存储在文件中和将对象转换成字节存储在文件里,可以参考一下

原文地址:https://www.cnblogs.com/baby12138/p/10284559.html