Skip to content

Instantly share code, notes, and snippets.

@BlogBlocks
Last active December 19, 2017 00:32
Show Gist options
  • Select an option

  • Save BlogBlocks/df011b4835fed21ddf219bdc2759fe4f to your computer and use it in GitHub Desktop.

Select an option

Save BlogBlocks/df011b4835fed21ddf219bdc2759fe4f to your computer and use it in GitHub Desktop.
"""
Counts / compares the number of lines in two files.
Usage:
python countlines.py a.txt b.txt
OR
import countlines
fname0 = 'a.txt'
fname1 = 'b.txt'
print len0(fname0),len1(fname1)
"""
import sys
fname0 = sys.argv[1]
fname1 = sys.argv[2]
def len0(fname0):
with open(fname0) as f0:
for i0, l0 in enumerate(f0):
pass
return i0 + 1
def len1(fname1):
with open(fname1) as f1:
for i1, l1 in enumerate(f1):
pass
return i1 + 1
if __name__ == "__main__":
#fname0 = 'a.txt'
#fname1 = 'b.txt'
print len0(fname0),len1(fname1)
@BlogBlocks

Copy link
Copy Markdown
Author

made public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment