Commit d3af87c5 by BellCodeEditor

auto save

parent 49a2427d
Showing with 11 additions and 5 deletions
......@@ -3,12 +3,18 @@
#file1.write("小兰:12本'\n'李文:9本'\n'张伟:16本")
#file1.close()
with open(r"C:\Users\HP\Desktop\新建文件夹\test.txt","r",encoding="utf-8") as file1:
abc=""
with open(r"C:\Users\HP\Desktop\新建文件夹\test.txt","w",encoding="utf-8") as file1:
#把文件里面的内容遍历在控制台
#判断小兰:12本在不在里边,在的话打印“数据在里面”出控制台
for i in file1:
print(i)
if '小兰:12本' in file1:
print("数据在里面")
file1.write("小兰:12本'\n'李文:9本'\n'张伟:16本")
for data in file1:
if '小兰:12本' in data:
data=data.replace("小兰:12本","小兰:15本")
abc+=data
#创建空的字符串变量,修改里边的数据,最后能够打印出新的内容出来
with open(r"C:\Users\HP\Desktop\新建文件夹\test.txt","w",encoding="utf-8") as file1:
file1.write(abc)
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