标签:
import os
import pickle
class File_handle(object):
def __init__(self,File):#判断文件是否存在
self.__file = File
if os.path.exists(self.__file) == False:
a={}
self.wirt(**a)
def read(self):# 读取数据
with open(self.__file,‘rb‘) as f:
locking_r = pickle.load(f)
return locking_r
def wirt(self,**args):# 保存数据
with open(self.__file,‘wb‘) as f:
pickle.dump(args,f)
return ‘success‘
Dict_chengji={‘zhangsan‘:90,‘lisi‘:99}#字典1
Dict_xingbie={‘zhangsan‘:‘nan‘,‘lisi‘:‘nv‘}#字典2
P_1=File_handle(‘./chengji‘)#实例化1 文件名chengji
P_1.wirt(**Dict_chengji)#写入字典1
print (P_1.read())#读取字典1
P_2=File_handle(‘./xingbie‘)
P_2.wirt(**Dict_xingbie)
print(P_2.read())
标签:
原文地址:http://www.cnblogs.com/illn/p/5483991.html