EnglishiPal项目 1.当用户创建新账号时,由于windows系统不兼容原来创建新文件语句,导致创建文件失败。 出现代码位置:main.py load_freq_history()函数 windows端修改 def load_freq_history(path): d = {} if os.path.exists(path): d = pickle_idea.load_record(path) else: # windows不支持 # os.mknod(path) f = open(path,'w') f.close() return d 2.当.pickle文件为空时,打开会报EOF错 出现代码位置:pickle_idea.py load_record()函数 修改建议 def load_record(pickle_fname): # 旧写法可能会出现EOFError # f = open(pickle_fname, 'rb') # d = pickle.load(f) # f.close() # return d # 新写法,也可以使用try/catch捕获 if os.path.getsize(pickle_fname) > 0: with open(pickle_fname, 'rb+') as f: unpickler = pickle.Unpickler(f) d = unpickler.load() return d return ''
else: # windows不支持 # os.mknod(path) f = open(path,'w') f.close() 不懂上面语句起什么作用?新建一个空文件? Hui
> unpickler = pickle.Unpickler(f) 为什么不直接用pickle.load(f)? Hui