频道栏目
首页 > 资讯 > Python > 正文

python功能实现:文件夹中保留文件中含有某些字段的行

18-06-28        来源:[db:作者]  
收藏   我要投稿

要求:

# -- coding: utf-8 --

import os

rootdir = ‘d:/a’

savedir = ‘d:/b’

list = os.listdir(rootdir)

for i in range(0,len(list)):

path = os.path.join(rootdir,list[i]).replace(‘\’,’/’)

if os.path.isfile(path):

#读取文件

with open(path,”r”) as f:

lines = f.readlines()

#写文件

with open(path,”w”) as f_w:

for line in lines:

if “there is problem” not in line:

continue

f_w.write(line)

f.close()

f_w.close()

相关TAG标签
上一篇:【基础练习习题】FJ的字符串
下一篇:ES6新特性之let和const指令实例介绍
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站