使用python读取txt文件的内容,并删除重复的行数方法
作者:猫猫与橙子 时间:2022-05-08 19:41:56
注意,本文代码是使用在txt文档上,同时txt文档中的内容每一行代表的是图片的名字。
#coding:utf-8
import shutil
readDir = "原文件绝对路经"
writeDir = "写入文件的绝对路径"
#txtDir = "/home/fuxueping/Desktop/1"
lines_seen = set()
outfile=open(writeDir,"w")
f = open(readDir,"r")
for line in f:
if line not in lines_seen:
outfile.write(line)
lines_seen.add(line)
outfile.close()
print "success"
最终结果在在写入文件内容中,没有重复内容。
来源:https://blog.csdn.net/qq_22764813/article/details/73187473
标签:python,txt,删除,重复,行数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一些SQL查询语法参考
2007-10-14 11:56:00
对python条件表达式的四种实现方法小结
2023-11-05 17:01:58
利用Python脚本实现传递参数的三种方式分享
2023-07-11 03:45:44
![](https://img.aspxhome.com/file/2023/0/83710_0s.png)
Python基于tkinter模块实现的改名小工具示例
2023-08-31 10:40:01
PHP实现PDF转图片的详细过程(使用imagick)
2023-09-07 13:27:34
![](https://img.aspxhome.com/file/2023/3/55523_0s.png)
asp生成不需要数据库的中奖码
2008-07-18 12:31:00
Anaconda下配置python+opencv+contribx的实例讲解
2021-04-10 21:28:33
![](https://img.aspxhome.com/file/2023/6/100276_0s.jpg)
python根据出生日期返回年龄的方法
2023-10-10 23:04:53
python3中str(字符串)的使用教程
2021-07-19 00:28:47
Python中OpenCV Tutorials 20 高动态范围成像的实现步骤
2022-04-02 07:24:20
![](https://img.aspxhome.com/file/2023/5/82935_0s.webp)
浅谈ThinkPHP5.0版本和ThinkPHP3.2版本的区别
2023-09-09 23:41:04
MySQL常用维护管理工具
2009-03-08 16:51:00
![](https://img.aspxhome.com/file/UploadPic/20093/8/phpmyadmin-39s.jpg)
内部系统是否也需要用户体验设计?
2010-11-30 21:47:00
![](https://img.aspxhome.com/file/UploadPic/201011/30/t1ya4qxihpxxxxxxxx-500-222-89s.png)
SQLSERVER 创建索引实现代码
2012-04-13 12:17:05
PHP实现sha-256哈希算法实例代码
2023-05-25 01:05:23
Python抽象基类的定义与使用方法
2021-07-31 21:48:43
![](https://img.aspxhome.com/file/2023/5/84145_0s.png)
基于标准的web项目开发模式探索
2013-12-12 15:05:25
![](https://img.aspxhome.com/file/UploadPic/20071/200713110544641s.gif)
Python中的__new__与__init__魔术方法理解笔记
2021-12-18 14:29:26
js和asp操作fso比较
2007-09-23 09:17:00
详解超星脚本出现乱码问题的解决方法(Python)
2022-11-21 02:40:42
![](https://img.aspxhome.com/file/2023/3/72963_0s.png)