#查询文件中含有特殊字符串的行 #!/usr/bin/python # -*- coding:utf- -*- import re file1 = open('test.txt','r+') istxt = re.compile(r'.*if.*',re.I) for line in file1.readlines(): line = line.strip() ifstr = re.findall(istxt,line) if ifstr: print ifstr #删除特定行(创建新文件,把不
工作中遇到的,本来用VBA写的,操作很慢,尝试用Python实现, 任务需求: 从原始的两张表中拷贝行到五张表中,如下表所示: source1和source2是一样的格式: one two three four five 1 2 3 11 11 22 22 33 33 44 44 55 55 目标表格有one,two,three,four,five. 将前三列和对应表的两列拷贝到目标表格中,目标表格中原始也需要删除有关键字的行(注释代码中实现了,但是有8000多行,删除很耗时
Python之文件处理-递归删除特定文件 #!/usr/bin/env python # -*- coding:utf-8 -*- import os def delete_particular_file(top): for root, dirs, files in os.walk(top, topdown=False): for file_name in files: if file_name.split('.')[-1] == 'ipynb': delete_file_name = os.p