亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用python統(tǒng)計(jì)文件行數(shù)示例分享

 更新時(shí)間:2014年02月21日 09:30:08   作者:  
當(dāng)文件的尺寸非常大的時(shí)候(10G之上吧),想知道行數(shù)是個(gè)問題,提供一個(gè)使用python統(tǒng)計(jì)文件行數(shù)的示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

import time

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

def getLineCount(filename):
    with open(filename,"r",encoding="utf-8") as f:
        return sum(line.count("\n") for line in block(f))
if __name__ == "__main__":
    import sys
    import os
    if len(sys.argv) != 2:
        print("error imput argument")
        sys.exit(-1)
    if not os.path.isfile(sys.argv[1]) :
       print(sys.argv + " is not a file")
       sys.exit(-1)
    start_time = time.time()
    print(getLineCount(sys.argv[1]))
    print(time.time() - start_time ,"seconds")

相關(guān)文章

最新評(píng)論