Last active
October 3, 2015 14:47
-
-
Save chetmancini/2471496 to your computer and use it in GitHub Desktop.
Count the lines of code in Python dir.
This file contains 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
def countLinesOfCode(path): | |
"""Procedure to count total lines of code in each file | |
""" | |
total = 0 | |
listing = os.listdir(path) | |
for fname in listing: | |
if fname[-2:] == "py": | |
with open(fname) as f: | |
for i, l in enumerate(f): | |
if len(l) > 80: | |
print "line " + str(i) + " of " \ | |
+ fname + " is too long." | |
subtotal = i + 1 | |
print string.rjust(fname, 25) + "\t" + str(subtotal) | |
total += subtotal | |
print total | |
if __name__ == "__main__": | |
countLinesOfCode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment