Last active
December 19, 2017 00:32
-
-
Save BlogBlocks/df011b4835fed21ddf219bdc2759fe4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
made public