Commit 55206e0b by BellCodeEditor

save project

parent 9d41970c
Showing with 8 additions and 7 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' new = ''# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
file = open("C:\\Users\\wzj\\Desktop\\test.txt",'w',encoding ='utf-8') file = open("C:\\Users\\wzj\\Desktop\\test.txt",'w',encoding ='utf-8')
file.write("小兰:12本\n小丽:11本\n李文:9本\n张伟:16本") file.write("小兰:12本\n小丽:11本\n李文:9本\n张伟:16本")
file.close() file.close()
with open("C:\\Users\\wzj\\Desktop\\test.txt",'r',encoding ='utf-8') as file: with open("C:\\Users\\wzj\\Desktop\\test.txt",'r',encoding ='utf-8') as file:
a = file.read() for data in file:
print(a) if "小丽" in data:
if "小强:11本" in file: data = data.replace('小丽','小白')
print("T") new += data
else: print(new)
print("F") with open("C:\\Users\\wzj\\Desktop\\test.txt",'w',encoding ='utf-8') as file:
file.write(new)
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