p y t h o n 写 t x t 文 件 python写txt文件 python写txt文件 with open("train_info.txt", "a", encoding="utf-8") as f: f.write("loss:"+str(total_loss)+"\n") # 如果文件存在,新写入内容会覆盖掉原内容,一定要注意!!! f.write("acc:"+str(correct/(len(train_loader)*batchsize))+"\n") # 如果文件存在,新写入内容会覆盖掉原内容,一定要注意!!!