pickle

 1 import pickle
 2 def say():
 3     print("hello One")
 4 info = {
 5     "test1":"111111",
 6     "test2":"222222",
 7     "test3":say #pickle可以dump函数(内存地址)
 8 }
 9 f = open("test.txt", "wb")
10 pickle.dump(info, f)# f.write(pickle.dumps(info)) #两句话相等 #一般一个文件只dump一次 要多dump几次的话 必须放在多个文件里
11 f.close()
12 ---------------------------------------------------------------
13 import pickle
14 def say():
15     print("hello Two")
16 f = open("test.txt", "rb") #无需encoding
17 
18 
19 byte_str = pickle.load(f) #byte_str = pickle.loads(f.read()) #两句话相同的意思
20 print(byte_str)
21 byte_str["test3"]()  #hello Two

 

posted @ 2017-06-20 16:04  Bird_getUpEarly  阅读(168)  评论(0编辑  收藏  举报