Commit 109de872 by BellCodeEditor

auto save

parent ad0971fd
Showing with 26 additions and 17 deletions
#写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
# a=open(r"C:\Users\Hp\Desktop\文档.txt","w",encoding='utf-8')
# a.write('小兰:12本\n')
# a.close()
# with open(r"C:\Users\Hp\Desktop\文档.txt","a",encoding='utf-8')as a: #a
# a.write("123\n")
# e=""
# with open(r"C:\Users\Hp\Desktop\文档.txt","r",encoding='utf-8')as a: #a
# for w in a: #遍历整个文档a
# if "123" in w: #判断123是不是在w里面
# w=w.replace("123","456")
# e+=w
# with open(r"C:\Users\Hp\Desktop\文档.txt","w",encoding='utf-8')as a:
# a.write(e)
with open(r"C:\Users\Hp\Desktop\文档.txt","w",encoding='utf-8')as a:
a.write("45646")
\ No newline at end of file
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
# a=open(r'C:\Users\Public\Desktop\14.txt','w',encoding='utf-8')
# a.write("以德服人") #写入
# a.close() #关闭
# with open(r'C:\Users\Public\Desktop\14.txt','w',encoding='utf-8') as a: #a是变量名
# a.write("哈哈哈哈\n")
#可以省略关闭文件close()
with open(r'C:\Users\Public\Desktop\14.txt','a',encoding='utf-8') as a: #a是变量名
a.write("下我的教案忘记了大\n")
#可以省略关闭文件close()
# with open(r'C:\Users\Public\Desktop\14.txt','r',encoding='utf-8') as a: #a是变量名
# a=a.read()
# print(a)
# with open(r'C:\Users\Public\Desktop\14.txt','r',encoding='utf-8') as a: #a是变量名
# for i in a: #遍历出所有的内容
# if '嘿嘿' in i: #用if判断查找的东西是否在文档里面
# print('在里面')
e=""
with open(r'C:\Users\Public\Desktop\14.txt','r',encoding='utf-8') as a: #a
for w in a: #遍历整个文档a
if "456" in w: #判断嘿嘿是不是在w里面
w=w.replace("456","779") #replace(被修改的,想要的)
e+=w #修改完之后不会发生改变因为我们用的是r只读模式所以不会发生改变
with open(r'C:\Users\Public\Desktop\14.txt','w',encoding='utf-8') as a:
a.write(e) #在这里我们用w模式添加进入我们上边修改的e
\ 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