def write_config(): print("新人脸训练结束") f = open('config.txt', "a") T = Total_face_num f.write(str(T) + " User" + str(T) + " \n") f.close() id_dict[T] = "User" + str(T) # 这里修改文件的方式是先读入内存,然后修改内存中的数据,最后写回文件 f = open('config.txt', 'r+') flist = f.readlines() flist[0] = str(int(flist[0]) + 1) + " \n" f.close() f = open('config.txt', 'w+') f.writelines(flist) f.close()