Skip to content

Instantly share code, notes, and snippets.

@okumura
Created November 24, 2019 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okumura/c4fb503bd6e6bdddc97171dbfce15dd8 to your computer and use it in GitHub Desktop.
Save okumura/c4fb503bd6e6bdddc97171dbfce15dd8 to your computer and use it in GitHub Desktop.
wc -l
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def wc_block_64k(name, blocksize=65536):
def blocks(f):
while True:
b = f.read(blocksize)
if b:
yield b
else:
break
with open(name, 'r') as f:
return sum(bl.count('\n') for bl in blocks(f))
print(wc_block_64k(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment