码迷,mamicode.com
首页 > 其他好文 > 详细

对文件内容去重后写入另一文件

时间:2018-06-26 17:22:04      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:txt   close   str   文件内容   文件   read   TE   /usr   append   

对文件内容去重后写入另一文件:

vi a1.py

#!/usr/bin/python

list = []
f = open(‘/root/ming.txt‘,‘r‘)
for str1 in f.readlines():
if not str1 in list:
list.append(str1)
f.close()
for b in list:
f2 = open(‘/root/ming2.txt‘,‘a‘)
f2.write(b)
f2.close()

:wq

python a1.py

对文件内容去重后写入另一文件

标签:txt   close   str   文件内容   文件   read   TE   /usr   append   

原文地址:http://blog.51cto.com/yangzhiming/2132885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!