详解python文件操作删除某行

使用continue跳过本次写循环就可以了

#文本内容Yesterday when I was young昨日当我年少轻狂The tasting of life was sweet生命的滋味是甜的As rain upon my tonguetastingI lived by night and shunned the naked light of daytasting123And only now I see how the time ran awaytasting tasting

登录后复制

将文本中的 tasting123删除 

with open("fileread.txt","r",encoding="utf-8") as f:    lines = f.readlines()    #print(lines)with open("fileread.txt","w",encoding="utf-8") as f_w:    for line in lines:        if "tasting123" in line:            continue        f_w.write(line)

登录后复制

更多详解python文件操作删除某行相关文章请关注PHP中文网!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2277668.html

(0)
上一篇 2025年2月27日 16:13:27
下一篇 2025年2月24日 19:59:53

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论