diy.py
651 Bytes
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'4
new_date=''
with open(r'C:\Users\Admin\Desktop\text.txt','r',encoding='utf-8') as filel:
for date in filel:
if '小强:10本'in date:
date=date.replace('小强:10本','小强:11本')
if '小强:10本'in date:
date=date.replace('小兰:10本','小兰:11本')
new_date +=date
#with open(r'C:\Users\Admin\Desktop\text.txt','w',encoding='utf-8') as filel:
# filel.write(new_date)
with open(r'C:\Users\Admin\Desktop\text.txt','r',encoding='utf-8') as filel:
a=filel.read
print(a)