Commit 637645cb by BellCodeEditor

save project

parent 17fc55be
Showing with 18 additions and 12 deletions
...@@ -7,17 +7,22 @@ f.write('张伟:16本\n') ...@@ -7,17 +7,22 @@ f.write('张伟:16本\n')
f.close() f.close()
with open(r"C:\Users\windows\Desktop\text.txt","a",encoding="utf-8") with open(r"C:\Users\windows\Desktop\text.txt","a",encoding="utf-8") as f:
f.write('小兰:19本\n') f.write('小兰:19本\n')
f.write('小丽:49本\n') f.write('小丽:49本\n')
f.write('文李:30本\n') f.write('文李:30本\n')
f.write('张伟:1本\n') f.write('张伟:1本\n')
f.close()
with open(r"C:\Users\windows\Desktop\text.txt","r",encoding="utf-8") new_data=()
a= f.read lines() with open(r"C:\Users\windows\Desktop\text.txt","r",encoding="utf-8") as f:
print(a) a= f.readlines()
for i in a:
print(a) print(a)
if"小兰:本" in i: for i in a:
print("数据在") print(a)
if"小兰:12本" in i:
print("数据在里面")
data=data.replace('小兰:12本','小兰298747本')
new_data=new_data+data
print (new_data)
with open(r"C:\Users\windows\Desktop\text.txt","w",encoding="utf-8") as f:
f.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