From 67306a2c8cc825c60fcdd3a6ec4b42b4579d54ce Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Fri, 22 Jul 2022 18:46:14 +0800 Subject: [PATCH] save project --- diy.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/diy.py b/diy.py index a6bceaf..c270af0 100644 --- a/diy.py +++ b/diy.py @@ -1,5 +1,10 @@ # 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' +new_data='' + with open(r'C:\Users\Administrator\Desktop\test.txt','r',encoding='utf-8') as file1: - for data in file1: - if '小强: 10本' in data: - print('数据在文件中') \ No newline at end of file + for data in file1: + if '小强:10本' in data: + data.replace('小强:11本') + new_data+=data +with open(r'C:\Users\Administrator\Desktop\test.txt','w',encoding='utf-8') as file1: + file1.write(new_data) \ No newline at end of file -- libgit2 0.25.0