标签:for end des out 正则表达 lin listdir pattern 依次
import re import sys import csv import os output=sys.stdout for file in os.listdir("C:/Users/Administrator/Desktop/Data_tidy/log_orig"): with open ("C:/Users/Administrator/Desktop/Data_tidy/log_orig/"+file,‘r‘,encoding=‘UTF-8‘) as f: fileName = re.split(‘\.‘,file) outputfile=open(‘C:/Users/Administrator/Desktop/Data_tidy/ios/‘+fileName[0]+‘.txt‘,‘w‘) #正则表达式体现过滤方式 pattern = re.compile(r‘(.*)(-----cpu)‘) for line in f: m=pattern.match(line) sys.stdout=outputfile if(m is not None): print (line,end = ‘ ‘) outputfile.close() sys.stdout=output
标签:for end des out 正则表达 lin listdir pattern 依次
原文地址:http://www.cnblogs.com/konkon/p/7612018.html