Commit 087bbada by BellCodeEditor

auto save

parent a62a24ee
Showing with 10 additions and 3 deletions
...@@ -2,8 +2,14 @@ ...@@ -2,8 +2,14 @@
#file=open(r"C:\Users\Administrator\Desktop\新建文件夹 (2)\book.txt","w",encoding="utf-8") #file=open(r"C:\Users\Administrator\Desktop\新建文件夹 (2)\book.txt","w",encoding="utf-8")
#file.write('小兰:12本') #file.write('小兰:12本')
#file.close() #file.close()
new_data=''
with open(r"C:\Users\Administrator\Desktop\新建文件夹 (2)\book.txt","r",encoding="utf-8") as file: with open(r"C:\Users\Administrator\Desktop\新建文件夹 (2)\book.txt","r",encoding="utf-8") as file:
for date in file: for data in file:
if '小兰:12本' in date: if '小兰:12本' in date:
print("数据在文件中") data=data.replace('小兰:12本','小兰:11本')
new_data+=data
with open(r"C:\Users\Administrator\Desktop\新建文件夹 (2)\book.txt","w",encoding="utf-8") as file:
file.write(new_data)
with open(r"C:\Users\Administrator\Desktop\新建文件夹 (2)\book.txt","r",encoding="utf-8") as file:
a=file.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