Commit effc03bb by BellCodeEditor

save project

parent 346a7fb3
Showing with 34 additions and 1 deletions
......@@ -8,7 +8,40 @@ filel.close()
with open(r'C:\Users\EDZ\Desktop\test.txt','a',encoding='utf-8')as filel:
filel.write('小强:10本\n')
filel.write('李明:15本\n')
new_data=''
with open(r'C:\Users\EDZ\Desktop\test.txt','r',encoding='utf-8')as filel:
for data in filel:
if'小强:10本' in data:
print('数据在文件中')
data=data.replace('小强:10本','小强:11本')
if '小兰:12本'in data:
data.replace('小兰12本','小兰:14本')
new_data +=data
with open(r'C:\Users\EDZ\Desktop\test.txt','w',encoding='utf-8')as filel:
filel.write(new_data)
with open(r'C:\Users\EDZ\Desktop\test.txt','r',encoding='utf-8')as filel:
a=filel.read()
print(a)
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