Commit ab7352d0 by BellCodeEditor

auto save

parent 023c124e
Showing with 12 additions and 4 deletions
......@@ -9,8 +9,16 @@
#file1.write("小强:12本")
#file1.write("李明:15本")
#with open(r'C:\Users\凤凰机器人金科3\Desktop\book.txt','r',encoding="utf-8") as file1:
#for i in file1:
#if "小强:12本"in i:
#print("数据在文件中")
new_data=""
with open(r'C:\Users\凤凰机器人金科3\Desktop\book.txt','r',encoding="utf-8") as file1:
for i in file1:
if "小强:12本"in i:
print("数据在文件中")
for data in file1:
if "小强:12本" in data:
data = data.replace("小强:12本","小强:11本")
new_data+=data
print(new_data)
with open(r'C:\Users\凤凰机器人金科3\Desktop\book.txt','w',encoding="utf-8") as file1:
file1.write(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