Commit 14ba73e5 by BellCodeEditor

auto save

parent 07837894
Showing with 15 additions and 1 deletions
...@@ -7,6 +7,19 @@ ...@@ -7,6 +7,19 @@
# filel.write('小强:12本\n') # filel.write('小强:12本\n')
# filel.write('李明:15本\n') # filel.write('李明:15本\n')
# filel.close() # filel.close()
#with open(r"C:\Users\mayi_robot\Desktop\test.txt",'r',encoding='utf-8') as filel:
# a = filel.read()
# print(a)
newb=''
with open(r"C:\Users\mayi_robot\Desktop\test.txt",'r',encoding='utf-8') as filel: with open(r"C:\Users\mayi_robot\Desktop\test.txt",'r',encoding='utf-8') as filel:
a = filel.read() for b in filel:
if '小强:12本'in b:
b=b.replace('小强:12本','小强:11本')
if '小兰:12本'in b:
b=b.replace('小兰:12本','小兰:14本')
newb+=b
with open(r"C:\Users\mayi_robot\Desktop\test.txt",'w',encoding='utf-8') as filel:
filel.write(newb)
with open(r"C:\Users\mayi_robot\Desktop\test.txt",'r',encoding='utf-8') as filel:
a=filel.read()
print(a) 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