Commit 3e03b45f by BellCodeEditor

save project

parent 98d47479
Showing with 12 additions and 4 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
new_data=''
files=open(r'C:\Users\HP\Desktop\test.txt','w',encoding='utf-8')
files.write('小兰:12本\n')
......@@ -7,6 +8,14 @@ with open(r'C:\Users\HP\Desktop\test.txt','a',encoding='utf-8') as files:
files.write('小丽:11本\n')
files.write('李文:9本\n')
with open(r'C:\Users\HP\Desktop\test.txt','r',encoding='utf-8') as files:
for data in files:
if '小丽:11本'in data:
print('小丽在数据中')
\ No newline at end of file
for data in files:
if '小丽:11本'in data:
data=data.replace('小丽:11本','小丽:12本')
new_data+=data
with open(r'C:\Users\HP\Desktop\test.txt','w',encoding='utf-8') as files:
files.write(new_data)
with open(r'C:\Users\HP\Desktop\test.txt','r',encoding='utf-8') as files:
a=files.read()
print(a)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment