Commit 6d29a321 by BellCodeEditor

save project

parent 318ddfef
Showing with 21 additions and 1 deletions
...@@ -7,4 +7,23 @@ ...@@ -7,4 +7,23 @@
# fill1.write('小强:10本\n李明:15本') # fill1.write('小强:10本\n李明:15本')
# fill1.close() # fill1.close()
# # with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','r',encoding='utf-8') as fill1:
# for data in fill1:
# if '小强:10本' in data:
# print("数据在文件中")
# if '小兰:12本' in data:
# print("小兰在数据中")
new_data=''
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','r',encoding='utf-8') as fill1:
for data in fill1:
if '小强:10本' in data:
data=data.replace('小强:10本','小强:11本')
if '小兰:12本' in data:
data=data.replace('小兰:12本','小兰:14本')
new_data+=data
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','w',encoding='utf-8') as fill1:
fill1.write(new_data)
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','r',encoding='utf-8') as fill1:
a=fill1.read()
print(a)
\ 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