Advertisement

OOP-Generator expression for log processing

阅读量:

generate log

复制代码
 # log_loop.py

    
  
    
 import sys
    
  
    
 inname = sys.argv[1]
    
 outname = sys.argv[2]
    
  
    
 with open(inname) as infile:
    
     with open(outname, "w") as outfile:
    
     warnings = (l for l in infile if "WARNING" in l)
    
     for l in warnings:
    
         outfile.write(l)
    
    
    
    
复制代码
 #sample_log.txt

    
  
    
 Jan 26, 2015 11:25:25    DEBUG        This is a debugging message.
    
 Jan 26, 2015 11:25:36    INFO         This is an information method.
    
 Jan 26, 2015 11:25:46    WARNING      This is a warning

全部评论 (0)

还没有任何评论哟~