Commit b8e380d0 by BellCodeEditor

save project

parent 87975676
Showing with 14 additions and 10 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' # 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
with open (r'D:\用户文件\xxx\test.txt','w',encoding='utf-8')as a: with open (r'D:\用户文件\xxx\test.txt','w',encoding='utf-8')as a:
a.write('小兰:12本\n小丽:11本\n李文:9\n张伟:16本') a.write('小兰:12本\n小丽:11本\n小强:10\n张伟:16本')
with open (r'D:\用户文件\xxx\test.txt','r',encoding='utf-8')as a: with open (r'D:\用户文件\xxx\test.txt','r',encoding='utf-8')as a:
b=a.read() #b=a.read()
print(b) #print(b)
c='小强:10本' new_a=''
for i in b: for i in a:
if c==i: if '小强:10本' in i:
print('在') i=i.replace('小强:10本','小强:11本')
break new_a+=i
with open (r'D:\用户文件\xxx\test.txt','w',encoding='utf-8')as a:
print('不在') a.write(new_a)
with open (r'D:\用户文件\xxx\test.txt','r',encoding='utf-8')as a:
b=a.read()
print(b)
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