Commit 4c5cab9a by BellCodeEditor

save project

parent 017bc6af
Showing with 8 additions and 4 deletions
...@@ -2,8 +2,12 @@ fil1=open(r'C:\Users\Administrator\Desktop\周珈伊.txt','a',encoding='utf-8') ...@@ -2,8 +2,12 @@ fil1=open(r'C:\Users\Administrator\Desktop\周珈伊.txt','a',encoding='utf-8')
fil1.write('小兰:12本\n小丽:11本\n李文:9本\n张伟:16本') fil1.write('小兰:12本\n小丽:11本\n李文:9本\n张伟:16本')
fil1.write('小强:12本\n') fil1.write('小强:12本\n')
fil1.close() fil1.close()
with open(r'C:\Users\Administrator\Desktop\周珈伊.txt','r',encoding='utf-8') as fil1: with open (r'C:\Users\Administrator\Desktop\周珈伊.txt','r',encoding='utf-8') as fil1:
a=fil1.read() a=fil1.read()
for i in a: for i in a:
if '小强:10本' in i: if '小强:12本' in i:
print('在文件中') a = fil1.replace('小强:12本','小强:10本')
\ No newline at end of file b = b+a
with open (r'C:\Users\Administrator\Desktop\周珈伊.txt','w',encoding='utf-8') as fil1:
fil1.write(b)
\ 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