Commit 2fe0d9b3 by BellCodeEditor

save project

parent d672820d
Showing with 10 additions and 3 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' # 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
# fell=open(r"C:\Users\23636\Desktop\toom.txt","w",encoding="utf-8") # fell=open(r"C:\Users\23636\Desktop\toom.txt","w",encoding="utf-8")
# fell.write('小兰:12本\n') # fell.write('小兰:12本\n')
# fell.write('小丽:11本\n') # fell.write('小强:10本\n')
# fell.close() # fell.close()
new_data=""
with open(r"C:\Users\23636\Desktop\toom.txt","r",encoding="utf-8") as fell: with open(r"C:\Users\23636\Desktop\toom.txt","r",encoding="utf-8") as fell:
for data in fell: for data in fell:
if '小强: 10本' in data: if '小强: 10本' in data:
data=data.replace('小强:10本','小强:11本')
if '小兰:12本' in data:
print('数据在文件中') print('数据在文件中')
if '小兰: 12本' in data: new_data+=data
print('数据在文件中') with open(r"C:\Users\23636\Desktop\toom.txt","w",encoding="utf-8") as fell:
fell.write(new_data)
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