Commit c3178ce2 by BellCodeEditor

save project

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