Commit 63dadbce by BellCodeEditor

auto save

parent 9f372067
Showing with 7 additions and 5 deletions
......@@ -4,10 +4,12 @@ with open(r"c:\Users\admin\Desktop\test.txt","a",encoding="utf-8") as file:
file.write("小明:12本\n")
with open(r"c:\Users\admin\Desktop\test.txt","r",encoding="utf-8") as file:
a=file.read()
new_data=""
with open(r"c:\Users\admin\Desktop\test.txt","r",encoding="utf-8") as file:
new_data=""
for data in file:
if "小王:12本" in data:
data=data.replace("小王:12本","小王:50本")
if "小王12本" in data:
data=data.replace("小王12本","小王:50本")
new_data=new_data+data
print(new_data)
\ No newline at end of file
# print(new_data)
with open(r"c:\Users\admin\Desktop\test.txt","w",encoding="utf-8") as file:
file.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