Commit cd496cab by BellCodeEditor

auto save

parent 59f687ca
Showing with 14 additions and 0 deletions
new_data=''#新建变量
with open('wanmei.txt','w',encoding='utf-8') as file:#写入文件
a=['小兰:12本\n','小强:15本\n','豆豆:30本\n']#写入序列字符串
file.writelines(a)
with open('wanmei.txt','r',encoding='utf-8') as file:#读取文件
for data in file:#遍历文件内容
if '小兰:12本' in data:
data=data.replace('小兰:12本','小兰:13本')#修改数据内容
new_data+=data#保存新文件
with open('wanmei.txt','w',encoding='utf-8') as file:#写入新文件
file.write(new_data)
小兰:13本
小强:15本
豆豆:30本
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