Commit ac65a94b by BellCodeEditor

save project

parent 4188651f
Showing with 7 additions and 3 deletions
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
#file1.close() #file1.close()
#with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','a',encoding='utf-8')as file: #with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','a',encoding='utf-8')as file:
# file.write("小兰:12本\n小丽:11本\n李文:9本\n张伟:16本") # file.write("小兰:12本\n小丽:11本\n李文:9本\n张伟:16本")
new_file=''
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','r',encoding='utf-8')as file: with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','r',encoding='utf-8')as file:
for data in file: for data in file:
if '小强:10本' in data: if '小强:10本' in data:
print("小强在目录中") data.replace('小强:10本','小强:11本')
if '小兰:12本' in data: if '小兰:12本' in data:
print("小兰在目录中") data.replace('小兰:12本','小兰:14本')
\ No newline at end of file new_file+=data
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','w',encoding='utf-8')as file:
file.write(new_file)
\ 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