Commit 51e7b79b by BellCodeEditor

auto save

parent 5ec53ebb
Showing with 18 additions and 0 deletions
# 写入数据
# with open(r'C:\Users\EDY\Desktop\test.txt','w',encoding="utf-8") as file:
# file.write("小兰:12本\n")
# file.write("小强:10本\n")
# file.write("李明:15本\n")
# 读取并修改数据 小强11本
new_data = ''
with open(r'C:\Users\EDY\Desktop\test.txt','r',encoding="utf-8") as file:
for data in file: # 遍历文件
if "10本" in data: # 判断10本在不在
data = data.replace("10","11") # 替换数据
new_data += data
# 重新写入
with open(r'C:\Users\EDY\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