From 826c146d98df4f451236812ba858e39cb720a60e Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sat, 28 May 2022 11:52:24 +0800 Subject: [PATCH] save project --- diy.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 diy.py diff --git a/diy.py b/diy.py new file mode 100644 index 0000000..dade0b3 --- /dev/null +++ b/diy.py @@ -0,0 +1,28 @@ +# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' +'''file1=open('C:\\Users\\xmbc\\Desktop\\book.txt','w',encoding='utf-8') +file1.write('小兰:12本\n') +file1.write('小丽:11本\n') +file1.write('李文:9本\n') +file1.write('张伟:16本\n') +file1.close() +file1=open('C:\\Users\\xmbc\\Desktop\\book.txt','a',encoding='utf-8') +file1.write('小强:12本\n') +file1.write('李明:15本\n') +file1.close() +with open('C:\\Users\\xmbc\\Desktop\\book.txt','r',encoding='utf-8') as file1: + for data in file1: + if '小强:12本' in data: + print('在') + break + elif '小强:12本' not in data: + print('no') + break''' +nwe='' +with open(r'C:\\Users\\xmbc\\Desktop\\book.txt','r',encoding='utf-8') as file1: + for data in file1: + if '小强:12本' in data: + data=data.replace('小强:12本','小强:11本') + nwe+=data + +with open(r'C:\\Users\\xmbc\\Desktop\\book.txt','w',encoding='utf-8') as file1: + file1.write(nwe) \ No newline at end of file -- libgit2 0.25.0