标签:func ofo 读取 write mode open lex 进制 基础
import pickledef sh(name):
print("hello,",name)
#序列化存储
info={‘key‘:‘mode‘,
‘lis‘:‘koud‘,
‘olo‘:234,
‘func‘:sh
}
f=open("text.txt","wb")
print(pickle.dumps(info)) #pickle序列化以二进制存储
f.write(pickle.dumps(info))
pickle.dump(info,f) #优化后的写法效果完全相同
f.close()
import pickle #只有在python语言里用
def sh(name): #序列化整个函数
print("hello3,",name)
print("hello4,",name)
f=open("text.txt","rb") #pickle反序列化读取的是二进制数据
data=pickle.loads(f.read())
data=pickle.load(f) #优化写法效果完全相同
print(data"func")
标签:func ofo 读取 write mode open lex 进制 基础
原文地址:http://blog.51cto.com/12992048/2176886