From 5d98c383103942d0ad2475712e9865ff8aaf2736 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sun, 24 Dec 2023 17:13:03 +0800 Subject: [PATCH] save project --- diy.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/diy.py b/diy.py index 73f4492..618f0b2 100644 --- a/diy.py +++ b/diy.py @@ -1 +1,20 @@ -# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' +t=open(r"C:\Users\双师12\Desktop\text.txt","w",encoding="utf-8") +t.write("小六:15\n小流:10") +t.close() + +with open(r"C:\Users\双师12\Desktop\text.txt","w",encoding="utf-8") + t.write("老六:90本") + +new_data="" +with open(r"C:\Users\双师12\Desktop\text.txt","r",encoding="utf-8") as t: + a=t.readlines() + print(a) + for i in a: + print(i) + if"老六:本"in i: + print("数据在") + data=data.replace("老六:90","老六:13") + new_data=new_data+data + print(new_data) +while open(r"C:\Users\双师12\Desktop\text.txt","w",encoding="utf-8") as t: +t.writable(new_data) -- libgit2 0.25.0