Commit 5860c677 by BellCodeEditor

save project

parent a8d02629
Showing with 21 additions and 0 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
data_new=''
with open(r"C:\Users\makcoo\Documents\test.txt","r",encoding="utf-8") as ed:
for data in ed:
if '李文' in data:
print("这个数据在里面")
print(data)
data=data.replace("李文-9","李文-11")
print(data)
data_new=data+data_new
with open(r"C:\Users\makcoo\Documents\test.txt","w",encoding="utf-8") as ed:
ed.write(data_new)
print("新的",data_new)
'''
ed.write("张伟-16\n")
ed.close()
'''
\ No newline at end of file
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