python 文件操作删除某行的实例
作者:Bigberg 时间:2022-09-21 12:15:18
使用continue跳过本次写循环就可以了
#文本内容
Yesterday when I was young
昨日当我年少轻狂
The tasting of life was sweet
生命的滋味是甜的
As rain upon my tongue
tasting
I lived by night and shunned the naked light of day
tasting123
And only now I see how the time ran away
tasting
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)
来源:http://www.cnblogs.com/bigberg/p/6495373.html
标签:python,删除某行
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现名片管理系统
2021-04-02 22:21:40
![](https://img.aspxhome.com/file/2023/8/90788_0s.jpg)
PyTorch中常用的激活函数的方法示例
2022-11-02 01:17:44
![](https://img.aspxhome.com/file/2023/5/85275_0s.png)
Access 2007简易入门手册
2008-12-04 13:12:00
![](https://img.aspxhome.com/file/UploadPic/200812/20081212115347643.jpg)
SQL语句练习实例之二——找出销售冠军
2011-10-24 19:52:45
Python 如何手动编写一个自己的LRU缓存装饰器的方法实现
2022-08-04 13:06:10
Python进阶之自定义对象实现切片功能
2023-09-22 11:28:31
Python爬虫实战之虎牙视频爬取附源码
2021-04-02 01:23:27
![](https://img.aspxhome.com/file/2023/9/64269_0s.png)
python 密码加密与解密的实现
2023-07-31 04:32:38
![](https://img.aspxhome.com/file/2023/3/61433_0s.png)
利用Python 实现图片转字符画
2022-05-06 11:31:01
![](https://img.aspxhome.com/file/2023/0/92510_0s.png)
Python第三方库face_recognition在windows上的安装过程
2023-07-27 02:51:29
使用python刷访问量的示例代码
2023-11-09 12:55:30
face++与python实现人脸识别签到(考勤)功能
2021-10-18 09:06:06
![](https://img.aspxhome.com/file/2023/4/84044_0s.jpg)
教你用Python脚本快速为iOS10生成图标和截屏
2022-03-04 05:08:28
![](https://img.aspxhome.com/file/2023/1/86211_0s.png)
Python如何实现FTP功能
2021-10-22 15:08:25
php异步:在php中使用fsockopen curl实现类似异步处理的功能方法
2023-07-21 14:48:58
解读ASP.NET 5 & MVC6系列教程(6):Middleware详解
2023-07-23 22:27:34
CSS Sprites 样式生成工具 2.0下载
2009-05-13 12:41:00
![](https://img.aspxhome.com/file/UploadPic/20095/13/20090512-pia7mda76k6mx2nwf2s3nx54tc-19s.jpg)
numpy模块中axis的理解与使用
2023-06-26 22:55:28
在Python中使用gRPC的方法示例
2021-02-02 16:20:21
![](https://img.aspxhome.com/file/2023/5/86565_0s.jpg)
pip install命令安装扩展库整理
2021-10-13 21:49:14
![](https://img.aspxhome.com/file/2023/8/97518_0s.png)