Python 统计IIS日志行数

__author__ = 'Administrator'
import codecs

def blocks(file, size=65536):
    while True:
        b = file.read(size)
        if not b: break
        yield b

with  codecs. open('h:/iis/u_ex141026.log', 'r','gbk', 'ignore') as f:
     print( sum(bl.count("\n") for bl in blocks(f)))

 

Python真短啊

posted @ 2014-10-30 10:44  张保维  阅读(213)  评论(0编辑  收藏  举报