Commit 3562b4c5 by BellCodeEditor

save project

parent 5b157c4b
Showing with 9 additions and 2 deletions
...@@ -5,9 +5,16 @@ ...@@ -5,9 +5,16 @@
#file1.write('李文:9本\n') #file1.write('李文:9本\n')
#file1.write('张伟:16本\n') #file1.write('张伟:16本\n')
#file1.close() #file1.close()
new_data=''
with open(r'C:\Users\Administrator\Desktop\book.txt','a',encoding='utf-8') as file: with open(r'C:\Users\Administrator\Desktop\book.txt','a',encoding='utf-8') as file:
file.write('小强:10本\n') file.write('小强:10本\n')
file.write('李明:15本\n') file.write('李明:15本\n')
for data in file: for data in file:
if '小强:10本' in data: if '小强:10本' in data:
print('数据在文件中') data=data.replace('小强: 10本', '小强:11本')
\ No newline at end of file new_data +=data
with open(r'C:\Users\Administrator\Desktop\book.txt','w',encoding='utf-8') as file:
file.write(new_data)
\ 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