python获取文件行数

    count = 0
    with open('/cm/com.file','rb') as f:
        while True:
            buffer = f.read(1024*8192)
            if not buffer:
                break
            count += buffer.count(b"\n")
    print(count)

 

posted @ 2020-11-30 22:29  明天OoO你好  阅读(1134)  评论(0编辑  收藏  举报