From c18fc4b840abec485afac3ac6e9d15fbe295ab74 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sat, 29 Jul 2023 11:46:39 +0800 Subject: [PATCH] save project --- diy.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 diy.py diff --git a/diy.py b/diy.py new file mode 100644 index 0000000..02a8d51 --- /dev/null +++ b/diy.py @@ -0,0 +1,15 @@ +# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' +# file=open(r"C:\Users\Lenovo\Desktop\新建文件夹\book.txt",'w',encoding='utf-8') +# file.write('小兰:12本') +# file.close() +new_date="" +with open(r"C:\Users\Lenovo\Desktop\新建文件夹\book.txt","r",encoding="utf-8") as file: + for date in file: + if '小兰:12本' in date: + date=date.replace('小兰:12本','小兰:10本') + new_date+=date +with open(r"C:\Users\Lenovo\Desktop\新建文件夹\book.txt","w",encoding="utf-8") as file: + file.write(new_date) +with open(r"C:\Users\Lenovo\Desktop\新建文件夹\book.txt","r",encoding="utf-8") as file: + a=file.read() + print(a) \ No newline at end of file -- libgit2 0.25.0