我先检查文件是否为空:
import osscores = {} # scores is an empty dict alreadyif os.path.getsize(target) > 0: with open(target, "rb") as f: unpickler = pickle.Unpickler(f) # if file is not empty scores will be equal # to the value unpickled scores = unpickler.load()
而且
open(target, 'a').close()在您的代码中什么也没做,您不需要使用
;。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)