Commit eecc1361 by BellCodeEditor

save project

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